How to apply a particular django database migration in heroku? - python

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

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

Django migrations not working from GitHub Actions

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.

Django Makemigrations not working in version 1.10 after adding new table

I added some table models in models.py for the first time running the app and then ran python manage.py makemigrations followed by python manage.py migrate. This works well but after adding two more tables it doesn't work again.
It created migrations for the changes made but when I run python manage.py migrate nothing happens. My new tables are not added to the database.
Things I have done:
Deleted all files in migrations folder and then run python manage.py makemigrationsfollowed by python manage.py migrate but the new tables are not still not getting added to the database even though the new table models show in the migration that was created i.e 0001_initial.py.
Deleted the database followed by the steps in 1 above but it still didn't solve my problem. Only the first set of tables get created.
Tried python manage.py makemigrations app_name but it still didn't help.
I have run into this problem before and found that running manage.py for specific tables in this fashion worked:
python manage.py schemamigration mytablename --auto
python manage.py migrate
Also make sure that your new table is listed under INSTALLED_APPS in your settings.py.
Can you post your models?
Have you edited manage.py in any way?
Try deleting the migrations and the database again after ensuring that your models are valid, then run manage.py makemigrations appname and then manage.py migrate.
You could try:
Deleted everything in the django-migrations table.
Deleted all files in migrations folder and then run python manage.py makemigrations followed by python manage.py migrate as you said.
If this doesn't work, try:
Deleted everything in the django-migrations table.
Deleted all files in migrations folder, use your old model.py to run python manage.py makemigrations followed by python manage.py migrate.
Add new model, run python manage.py makemigrations followed by python manage.py migrate again.

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

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