Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

South won't generate or apply migrations for existing app, with changes to migrate

I'm using South to generate and apply migrations, rather than managing that myself. Unfortunately, South is refusing to actually do anything. Transcript below:

[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py schemamigration mainapp --auto
You cannot use --auto on an app with no migrations. Try --initial.
[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py schemamigration mainapp --initial
 + Added model mainapp.CompanyUK
 + Added model mainapp.CompanyName
 + Added model mainapp.Individual
 + Added model mainapp.Director
 + Added model mainapp.DirectorsIndividual
 + Added model mainapp.DirectorsCorporate
 + Added model mainapp.ShareCapitalClass
 + Added model mainapp.Member
 + Added model mainapp.MembersIndividual
 + Added model mainapp.MemberGeneric
 + Added model mainapp.CompanyManager
 + Added model mainapp.PendingRegistration
 + Added model mainapp.PendingAuthorisation
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate mainapp
[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py migrate mainapp
Running migrations for mainapp:
- Nothing to migrate.
 - Loading initial data for mainapp.
No fixtures found.
[graffias:~/testing.tustincommercial.com/oneclickcos]$ 

As you can see, South thinks there is nothing to do. However, the last three models are completely new, and have no table in the database.

Is there anything I can do, short of zapping the database to get South working again?

I have no intention of manually writing migrations for the rest of the project, but if it would help, I would write one migration.

like image 220
Marcin Avatar asked Sep 04 '11 15:09

Marcin


People also ask

Why Makemigrations is not working?

This may happen due to the following reasons: You did not add the app in INSTALLED_APPS list in settings.py (You have to add either the app name or the dotted path to the subclass of AppConfig in apps.py in the app folder, depending on the version of django you are using). Refer documentation: INSTALLED_APPS.

What is the difference between Makemigrations and migrate in Django?

migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.

How do I reverse migration in Django?

By doing python manage.py migrate app B (or A; both works) . Remove the migration files A and Y for time being from the project location. Now unapply B, by doing python manage.py migrate app X .


1 Answers

I guess you got yourself in trouble by not starting out with ./manage.py convert_to_south mainapp. Maybe you can correct this by doing :

(1) Make South believe you didn't perform the first migration, so go to zero

./manage.py migrate --fake mainapp zero

(2) Migrate for real to the first migration.

./manage.py migrate mainapp

But for what I can make of your question you already had some models in your database made without South, otherwise you wouldn't have had to use --initial. If so it will probably complain about columns already existing.

You can change this situation by :

(1) Wiping out the first schemamigration by deleting mainapp/migrations/0001_initial.py. You don't need to fiddle with the South database table directly, --delete-ghost-migrations will take care of this.

(2) ./manage.py syncdb South expects the database to be in sync with the models.

(3) ./manage.py convert_to_south mainapp to actually let South handle the database and the migrations.

(4) ./manage.py migrate --delete-ghost-migrations mainapp to move to the first migration and deleting the old first migration you deleted from migrations/ from the database

like image 54
Density 21.5 Avatar answered Oct 16 '22 06:10

Density 21.5