Django migrations not working from GitHub Actions - python

I have the command heroku run -a ${{ secrets.HEROKU_APP_NAME }} python manage.py migrate set to run after pushing master to Heroku. It runs without errors (below is it's the output):
Running python manage.py migrate on ***... ?
Running python manage.py migrate on ***... done
But the migrations don't actually run. What could be the problem?

Found the answer in the Heroku docs. Essentially, add release: python manage.py migrate as the first line in the Procfile. It doesn't tell me why it's not working from the GH action, but it gets the job done.

Related

Migrations in DJango

I am having DJango migrations problem while making migration following error is coming.
When I run my applications using python manage.py runserver it shows this :-
However, running python manage.py makemigrations shows no changes detected
And Above three images are result after running python manage.py migrate.
What is the problem with this?
When the *table> already exists Error happens, it is usually due to deleting and rerunning the initial migration or models.py file. For these scenarios,
python manage.py makemigrations <app_name>
python manage.py migrate --fake-initial <app_name>
Or if you want to fake only one migration file
python manage.py migrate <migration_file_number> --fake <app_name>
--fake-initial tells Django to mark initial migration as migrated without actually running its corresponding SQL.
Django's migration document may be helpful
looks like you changed the database or migration files manually.
try to re-create the database.
delete the DB file
delete all migrations files (keep the init file)
run create migrations command
run migrate command

Heroku collect static manual

Is there a way that I can run collectstatic manually in my terminal and disable heroku from doing it automatically? I want to run
python3 manage.py collectstatic
However, on Heroku, it defaults to
python manage.py collectstatic
If I disable collectstatic on heroku, can someone give me steps to do it manually please.
First of all, you need to turn it off, like this
heroku config:set DISABLE_COLLECTSTATIC=1
Then you deploy like usually
git push heroku master
Then you have to run migrations
heroku run python3 manage.py migrate
Now you run collectstatic using bower
heroku run 'bower install --config.interactive=false;grunt prep;python3 manage.py collectstatic --noinput'
And then this is optional, this is how you turn them on again for future deploys
heroku config:unset DISABLE_COLLECTSTATIC

Python Manage.py Commands Not Recognized on Heroku

Trying to run heroku run python manage.py migrate --remote [my app] and it is outputting a list of subcommands. Tried various other django commands with the same result, everything from 'shell' to some custom commands I invented.
heroku run python is working fine as well has other heroku commands (run ls). is there a problem with django apps at the moment? i haven't edited my heroku settings or done anything related to heroku (rolled back to much farther-back deploys and still broken, so isn't any recent code changes)
Running python manage.py help migrate on tempotrader-staging... up, run.7740
/app/.heroku/python/lib/python2.7/site-packages/stream_django/enrich.py:3: RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated in favor of the new application loading system.
from django.db.models.loading import get_model
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[account]
account_emailconfirmationmigration
account_unsetmultipleprimaryemails
[auth]
changepassword
createsuperuser
[avatar]
rebuild_avatars
[charting]
update_portfolios
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
shell
showmigrations
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlmigrate
sqlsequencereset
..... etc
Heroku fixed it!
Image of Fix
Full link here of status/incident report

How to apply a particular django database migration in heroku?

I uploaded my modified code with some changes in models. When I run heroku run python manage.py migrate app to apply the database migrations it gave me an error
CommandError: Conflicting migrations detected (0004_auto_20150819_0827, 0008_auto_20150813_1444 in app).
To fix them run 'python manage.py makemigrations --merge'
So when I run heroku run python manage.py makemigrations --merge it gave me output:
Created new merge migration /app/app/migrations/0009_merge.py
Now how can apply this migration to my database ?
Maybe
heroku run python manage.py migrate
or to see what it's going to apply:
heroku run python manage.py showmigrations

South Migration Error

I am trying to learn Django by setting up one of the projects I found on github. Afetr I ran the syncdb command it showed
Not synced (use migrations):
- django_extensions
- djangoratings
- profiles
- guardian
(use ./manage.py migrate to migrate these).
When I am running "python manage.py migrate app" , it gives
AttributeError: 'module' object has no attribute 'Migration'.
I also ran schemamigration app --auto and --initial as well. But nothing seems to be working. Can somebody point out where I am going wrong.
Are you actually running python manage.py migrate app exactly? If you want to migrate all apps, just run python manage.py migrate. (without app) If there is an app actually named app that you want to run migrations for, then you would do what you did.
If you still get the error after running python manage.py migrate, then there must be an invalid migration file somewhere. I would migrate each app individually like this:
python manage.py migrate django_extensions
python manage.py migrate djangoratings
... etc.
to find the app with bad a migration file. Once you find the app, look in the migrations folder of the app to find any empty migration files.
First thing you must run initial migration.
python manage.py schemamigration --initial
You are getting this error because of your project structure or there is some issue with your south package .try to remove and reinstalling south.
You need to see that there should not be any extra .py file in your migration folder.

Categories