2

I have a custom django management command that initializes an apps migrations. Trouble is, south does not detect the new migrations in the command.

for app in custom_apps:
    call_command('schemamigration', app, initial=True)
    call_command('migrate', app, fake=True)

This creates the initial migration, but does not apply them.

? You have no migrations for the 'profile' app. You might want some.

I tried using convert_to_south, but it only converts the first app in the list, and then gives this error for the rest of them

This application has no models; this command is for applications that already have models syncdb'd.
Make some models, and then use ./manage.py schemamigration candidates --initial instead.

The commands work if I run them manually.

Can't figure out what's going on.

elssar
  • 5,651
  • 7
  • 46
  • 71
  • Did you run syncdb before running the management command? Also, refer to this SO question: http://stackoverflow.com/questions/21309371/django-not-creating-db-tables-for-models-neither-with-syncdb-nor-south – Esteban Aug 12 '14 at 04:49
  • Yes I ran `syncdb` before. That is not the problem. The problem is that it doesn't work from the django shell, or from a management command. Have tested with two different django projects – elssar Aug 12 '14 at 12:00
  • have you tried running `call_command('schemamigration', app, initial=True)` twice? Sometimes I get that same error when running `schemamigration app --init` and then I re-run the command and it works. – Aaron Lelevier Aug 12 '14 at 19:10
  • I too have same issue, did you find any solution?? – vipin Oct 11 '15 at 13:25

1 Answers1

1

I think you are missing an argument to the migrate command. See here) a small example for fake converting your app. Their command looks like this:

./manage.py migrate myapp 0001 --fake

So, you could try something like this:

for app in custom_apps:
    call_command('schemamigration', app, initial=True)
    call_command('migrate', 0001, fake=True)

If you want to convert all your apps at once, you could use this code outside your loop.

call_command('migrate', 0001, fake=True, all=True)

Normally, this last command should fake applying the initial migrations for all your apps.

Good luck.

AdelaN
  • 3,366
  • 2
  • 25
  • 45
  • Don't need to pass 0001. If you don't supply the migration number, south will migrate to the last available migration, so that isn't the problem. Anyways, a lot of 3rd party apps have more than 1 migration, so when fake migrating them passing 0001 isn't a good idea. – elssar Aug 14 '14 at 11:36
  • If your apps already have migrations, then calling schemamigration with initial=True kind of beats the purpose, doesn't it? Because afaik, that command is used only for the first migration... – AdelaN Aug 14 '14 at 12:48
  • My apps don't have migrations, was just giving an example for why passing 0001 isn't always required or the best option when applying fake. – elssar Aug 14 '14 at 12:50