Assistance for deploying django app to heroku

85 views
Skip to first unread message

ejike....@gmail.com

unread,
Apr 23, 2021, 7:55:08 AM4/23/21
to Django users
Good day All,

I am trying to deploy my django app to heroku but i keep getting this error in the screenshot attached.

Please can anyone assist in me in finding a solution to this and where the issue could be coming from.

Looking forward to your replies.

Thanks and BR,

Ejike
Screenshot 2021-04-23 at 12.44.34.png
Screenshot 2021-04-23 at 12.48.33.png

Mohammad Anarul

unread,
Apr 23, 2021, 11:09:47 AM4/23/21
to django...@googlegroups.com
kindly shere your code....

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c7fd9ab-20a6-43f3-9793-06ea0f4220c6n%40googlegroups.com.

Sujayeendra G

unread,
Apr 23, 2021, 2:29:01 PM4/23/21
to django...@googlegroups.com

Hi, 

You can see IntegrityError: fixtures you are updating trying to find user with user_id=1 which are not available in your db. Try to create one user and migrate again. Or if the App is still in the development stage. Delete DB and migrate again. It may work. 

Thank you 

Regards
Sujay


--

Ejike Enyinnaya

unread,
Apr 23, 2021, 2:42:35 PM4/23/21
to django...@googlegroups.com
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


Sujayeendra G

unread,
Apr 23, 2021, 2:51:41 PM4/23/21
to django...@googlegroups.com
Please explain all your steps clearly. 

How are you creating fixture.json, Are you taking all data dump or only book model dump ??


Kasper Laudrup

unread,
Apr 23, 2021, 2:54:08 PM4/23/21
to django...@googlegroups.com
On 23/04/2021 20.41, Ejike Enyinnaya wrote:
> I did a git add ., git commit -m and git push heroku master

Not sure if it's related, but it's possible: This is not how you should
use revision control (git).

You should keep your source files under revision control, not just
blindly add everything and committing it with an empty commit message.
Then you might as well not use any kind of revision control at all.

It might be slightly off topic and not related to your problem, but on
the other hand, there's a huge chance that you have added a bunch of
stuff like your database file and you have zero way of tracking what you
have actually changed.

Not sure if this has every worked for you, but if you have a similar
problem and it used to work and then suddenly didn't, using revision
control like git can be an enormous help.

Do yourself a huge favor and learn how to use revision control.

Kind regards,

Kasper Laudrup

OpenPGP_signature

Irfan Khan

unread,
Apr 23, 2021, 4:57:35 PM4/23/21
to django...@googlegroups.com
check this one 
try to run the console 
$ python manage.py sqlsequencereset your_app_name 
it will give you the psql queries. run those queries on PSQL console and then try to  run loaddata.

check below link 



With Regards,
Irfan khan





--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Ejike Enyinnaya

unread,
Apr 24, 2021, 11:02:46 AM4/24/21
to django...@googlegroups.com, lau...@stacktrace.dk
Good day Kasper,

Hi Kasper, 

Thanks for your response. The "git" commands I put in the email was not just to give any one an idea of what commands I had run but on my CLI, I ran the proper git commands with the proper messages and not leaving it empty.
BR,
Ejike Chiboka
08022224537; 08166516400

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Ejike Enyinnaya

unread,
Apr 24, 2021, 11:05:28 AM4/24/21
to django...@googlegroups.com, lau...@stacktrace.dk
Good day Kasper,

Thanks for your response. 

The git commands I put in the email was just to give a summary of what I had done and not the full details, that way my email is not too long and cumbersome to read.

I can assure you on my CLI, I ran the proper git commands putting in the right information and not leaving it empty.

BR,
Ejike Chiboka
08022224537; 08166516400

On Fri, Apr 23, 2021 at 7:53 PM Kasper Laudrup <lau...@stacktrace.dk> wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Jim Illback

unread,
Apr 24, 2021, 4:39:01 PM4/24/21
to Django Users
I didn’t see a “createsuperuser" command. Was that done or is it part of your fixtures.json load?

Jim

Ejike Enyinnaya

unread,
Apr 26, 2021, 6:59:39 AM4/26/21
to django...@googlegroups.com
Good day Jim,

My process from beginning includes:

1. I reset the database: rm -f db.sqlite3
2. python manage.py migrate
3. In django admin platform: I added all the books information from the fixtures.json and tied it to the user which is admin
4. Implemented a new fixtures.json
5. ran python manage.py makemigrations
6. ran python manage.py migrate
7. git add .
8. git commit -m "[updated information here]"
9. git push origin master
10. git push heroku master
11. heroku run python manage.py migrate
12. heroku run python manage.py loaddata books/fixtures.json (This is where i get the error)


BR,
Ejike Chiboka
08022224537; 08166516400

Reply all
Reply to author
Forward
0 new messages