django-background-tasks migrations on heroku - django

I am trying to migrate dajngo-background-tasks on my app hosted in heroku. Migrations worked normally locally but when I tried to run:
heroku run python manage.py migrate
It returned 'No migrations to apply'
I've added 'background_task', to INSTALLED_APPS
I ran
heroku run python manage.py makemigrations background_task
And it created the required migrations
I even tried running
heroku run python manage.py migrate background_task
causing "CommandError: App 'background_task' does not have migrations."
PS: One thing I noticed is that when running migrate locally I get this text
Apply all migrations: admin, background_task, auth, contenttypes, sessions, <my_app>
But when I run it on the server I get
Apply all migrations: admin, auth, contenttypes, sessions, <my_app>
Every form of help will be very much appreciated!

You must not run makemigrations via heroku run. You must run it locally, commit the resulting migrations and push them to heroku, then run them there.

This is due to missing migrations in the django-background-tasks package. This issue has been fixed in the latest version. If you install 1.1.9 the deployment to heroku should work.

Related

Django migration error in heroku postgres

I've just deployed my Django website on Heroku and while running the command to make migrations it shows a lot of migrations to apply but when I try to migrate it, it says no migrations to apply.
Here's a photo of it.

Django 2.1 NOT NULL Constraint Failed When Creating Super User

I've been using Django for several months now without any issue but when I went to create a new project and add the super-user, I get the following error:
django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login
All migrations have been created and applied successfully. I have destroyed and recreated the database a half dozen times to no avail. App migrations run without any problem whatsoever and this is the first time I've encountered this issue in an Django project.
I just realized this message was buried in the dozens of lines of error messages:
You have 12 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Running just manage.py migrate and/or manage.py migrate appname did not apply the required system migrations. I had to do each one individually this time for some reason.
After running each one individually I was able to create a superuser without a problem:
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
I've never had to do that before, however. If anyone knows a reason as to why that happened I'd love to know but I've solved the main issue for now.
I'm too used
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
this helped for me
python manage.py createsuperuser

Django on Heroku - ProgrammingError at / relation "..." does not exist

I'm getting this error. I know you usually get this error because the databases wasn't properly migrated.
When I run heroku local web, the website works fine when I go to localhost:5000.
However after I deploy the app to heroku with git push heroku master, the error comes up.
In other words, it works in my local environment. But it does not work after deploying to heroku.
I have Heroku-Postgres installed as an add-on in heroku.
What could be causing this?
excute migrations and makemigrations in bash heroku. open the terminal in the local project folder and give the following commands:
heroku run bash
~$ ./manage.py makemigrations
~$ ./manage.py migrate
~$ exit
The following steps did it for me
Make all the necessary migrations (python manage.py makemigrations) and migrate (python manage.py migrate) locally,
push to heroku master
and finally running heroku run python manage.py migrate
Solved the issue
I experienced the same error after making a change to a model and then deploying this change to heroku.
The only way I managed to fix this problem was to do the following:
Reset the database in heroku
Delete the migrations files from the migrations folder for the broken app locally (but keep the directory and the __init__.py file)
Run python manage.py makemigrations and python manage.py migrate. This will repopulate the migrations folder with clean migration files.
Push changes to master (ensure that you do not have migrations directories in .gitignore files.
Deploy changes to heroku
Run the heroku shell heroku run bash
Run python manage.py migrate
I was able to do this because my tables did not have much data in, but I would try to avoid resetting the database if I had more data in my tables.

Deploying Django app to Heroku via CircleCI: How to migrate database?

How can I run python manage.py makemigrations and python manage.py migrate automatically when deploying a Django app to Heroku via CircleCI. It seems all commands run local to CircleCI, but not on the deployed application in production.
Is there a way?
python manage.py makemigrations should be running locally, and you may commit the migration files along with the code.
Regaridng the migrations, open your Procfile and add this line: release: python manage.py migrate.
This will tell Heroku to migrate before deploying a new version of your code.

Migrations failing on Heroku

I have a Django-CMS project running on a Cedar stack using Django 1.7.1 and Python 3 at Heroku.
I can create a migration just fine using: heroku run python manage.py makemigrations which returns:
Migrations for 'zinnia':
0002_entry_content_placeholder.py:
- Add field content_placeholder to entry
However, running the migration via: heroku run python manage.py migrate returns:
Operations to perform:
Synchronize unmigrated apps: mptt, tagging, djangocms_admin_style, localflavor, django_comments, robots, ckeditor, sekizai, compressor, cmsplugin_plaintext, storages
Apply all migrations: admin, cms, zinnia, sessions, contenttypes, sites, auth, djangocms_link, djangocms_file, djangocms_picture, djangocms_text_ckeditor, menus
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration,
and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run
'manage.py migrate' to apply them.
Re-running makemigrations and migrate simply returns the same error statement. What am I doing wrong?
im not so sure on that one, but after you ran the Migration, the file created:
0002_entry_content_placeholder.py
is as you notice, the second migration file.
If its an option for you, you could try to delete/rename the migration folder/files and run makemigrations again.
I got kinda the same error some time ago, and if i remember right, that did the trick.
Sorry for bad english