South 'nothing to migrate' message after successful schema migration - python

I have a Django app that I added South to, performed some migrations with, and runs as expected on my local machine. However, I have had nothing but database errors after pushing my project to Heroku.
In trying to deal with one database error I am experiencing, I attempted a test where I deleted one of my models, pushed the edited models file to Heroku and ran:
heroku run python manage.py schemamigration django_app test_remove_pub --auto
This seemed to work fine. I got back the message:
Running `python manage.py schemamigration apricot_app test_remove_pub --auto` attached
to terminal... up, run.6408
- Deleted model django_app.Publication
- Deleted M2M table for journalists on django_app.Publication
- Deleted M2M table for tags on apricot_app.Publication
Created 0006_test_remove_pub.py. You can now apply this migration with: ./manage.py
migrate django_app
So, South appeared to do everything I expected - it deleted my model and its many to many relationships and made the appropriate migration file. Next, I enter:
heroku run python manage.py migrate django_app
And I get back:
Running `python manage.py migrate django_app` attached to terminal... up, run.4792
Running migrations for django_app:
- Nothing to migrate.
- Loading initial data for django_app.
Installed 0 object(s) from 0 fixture(s)
Why would it say "nothing to migrate" when obviously there are things to migrate??

After you change the models, you need to do :
heroku run python manage.py schemamigration django_app --auto
if anything has changed
and then run
heroku run python manage.py migrate django_app
South applies migrations based on the entries in this database table: south_migrationhistory. So if you want to manually override it,
Remove all the entries with column app_name of the models you changed
Manually remove all the related tables. You can get a list of all the tables by typing this in the django shell:
from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app, include_auto_created=True):
print model._meta.db_table
Remove the migrations/ folder related to the app
Do a fresh migration: ./manage.py schemamigration app_name --initial
Apply the migration ./manage.py migrate app_name

Related

django doesnt run a specific migration (it skipped) in production

when I ran the makemigrations it returns
users/migrations/0002_remove_profile_image.py
- Remove field image from profile
But when i ran migrate users 0002.. it said CommandError: Cannot find a migration matching '0002_remove_profile_image.py' from app 'users'
when i ran migrate it said
No migrations to apply.
Your models in app(s): 'users' 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.
what can i do?
i am deploying on heroku
It seems you are using the migration name with the .py:
./manage.py migrate users 0002_remove_profile_image.py
But the correct usage is without it, so just remove that:
./manage.py migrate users 0002_remove_profile_image
or just the short-hand:
./manage.py migrate users 0002
Sorry, my bad. I was running with heroku run I should have run locally first.

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 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.

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.

Issues with creating table via migration

I have created a model and when I try to create the table via migration using python manage.py migrate app_name and in response I get
- Nothing to migrate.
- Loading initial data for app_name.
Installed 3 object(s) from 1 fixture(s)
But the table is not created , its a simple process but I don't know why the table is not created. The db used is postgresql and I have also used syncdb but doesn't work .
It seems you haven't created any migrations. You need to create them, before they can be run.
For app's initial first migration you run:
./manage.py schemamigration your_app --initial
For following migrations you run (provided you want to create an automatic migration):
./manage.py schemamigration your_app --auto
You can see more examples in the tutorial.

Categories