Hi Guys,
This is the error I am getting:
(first_django_app) ➜ first_django_app git:(master) heroku run python manage.py loaddata books/fixtures.json
Running python manage.py loaddata books/fixtures.json on ⬢ gotbooksapp... up, run.6617 (Free)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.ForeignKeyViolation: insert or update on table "books_book" violates foreign key constraint "books_book_user_id_4b809191_fk_auth_user_id"
DETAIL: Key (user_id)=(1) is not present in table "auth_user".
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 131, in loaddata
connection.check_constraints(table_names=table_names)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 285, in check_constraints
cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table "books_book" violates foreign key constraint "books_book_user_id_4b809191_fk_auth_user_id"
DETAIL: Key (user_id)=(1) is not present in table "auth_user".
I have done the following: rm -f db.sqlite3
run python manage.py makemigrations
run python manage.py migrate
I had to add all the information again as the database had been cleaned out
I then implement fixtures.json locally
I did a git add ., git commit -m and git push heroku master
I did run heroku run python manage.py migrate
I finally run python manage.py loaddata books/fixtures.json
I still have the same errors again
BR,
Ejike Chiboka
08022224537; 08166516400