5

I am using django-south for migrating database tables in a django project. And I am renaming a model as discussed in a previous question:

    # Renaming model from 'Foo' to 'Bar'                                                                                                                      
    db.rename_table('myapp_foo', 'myapp_bar')                                                                                                                        
    db.send_create_signal('myapp', ['Bar'])

However, I use fabric to automatically deploy my application to production servers, and I want the migrations to run without any user input. For this, I run the migration command with the noinput option as follows

python manage.py migrate --noinput

This works fine except that the send_create_signal does not remove stale contenttypes in this mode.

This is because the django contenttype managament command update_contenttypes only removes the stale contenttypes if input is given.

I could replicate the update_contenttypes command directly in the south migration, but that does not seem like a good solution. Does anyone have suggestions on how to trigger the removal of the contenttypes without repeating what is in the django command?

Community
  • 1
  • 1
yellowcap
  • 3,985
  • 38
  • 51
  • why are you running migrate with --noinput? – Thomas Nov 27 '13 at 02:20
  • This is because I want to deploy to the production servers without human interaction. I am deploying the codebase from the repository to the servers fully automated using fabric scripts. To be able to doing this I am looking for a solution without human input here. – yellowcap Nov 27 '13 at 08:44
  • 1
    Then you should probably just either duplicate the command, or create a datamigration and manually delete the affected content_types. – Thomas Nov 27 '13 at 10:43
  • You are probably right. I was hoping there was a more elegant solution. If the `update_contenttypes` funciton had an option to force the update without input that would be ideal. But since it doesn't, it seems like doing it explicitly in the migration is the best solution. – yellowcap Nov 27 '13 at 17:14
  • Maybe you could you pipe a "y" character as input to the command with fabric instead of noinput? – Emil Stenström Sep 24 '15 at 19:44

1 Answers1

1

In my experience, running manage.py syncdb --all works some, but not all of the time when South is involved. You might try giving it a go, as it has worked for me in the past, certainly when removing stale models from the content-types table.

Steadman
  • 538
  • 4
  • 12