11

I am removing an unnecessary table and model from our Django website. I have removed all foriegn key references before the migrations.DeleteModel(...) is called, but I still am receiving the following prompt when I run the migration:

The following content types are stale and need to be deleted:

myapp | MyDeletedModel

Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you're unsure, answer 'no'.

Type 'yes' to continue, or 'no' to cancel: yes

I am confused why I am receiving this prompt is there a way I can stop this prompt from showing when we go live? we use a CI environment where we do not have users available to answer "yes" or "no"

Thanks

1 Answer 1

14

The contenttypes framework contains references to model tables. In this case, you have a stale reference to the table you just deleted. It is perfectly safe to answer yes and remove the stale contenttype. It would be a different story if you renamed a table that had a GenericForeignKey pointing to it, in which case other objects would have a ForeignKey to that ContentType, and the delete would cascade along those relations.

In a live environment, you can pass the --noinput option to suppress this prompt. However, it will default to no. It's usually not really a problem to have some stale contenttypes lying around.

7
  • Thanks @knbk, I will check with our ci guy to see how we run the migrations for --noinput, if we answer this once, will it remember the answer, or will we be prompted every migration? Jun 1, 2015 at 15:25
  • You'll be prompted every time you run a migration that renames or removes a model.
    – knbk
    Jun 1, 2015 at 15:26
  • ok, I am looking at the django_contenttype table. I no longer see a row for the table when I answered yes. but If I answer no, it will prompt the next migration, right? Jun 1, 2015 at 15:31
  • 1
    The system is quite conservative if you use the --noinput option. For contenttypes, it would always answer no.
    – knbk
    Jun 1, 2015 at 16:22
  • 2
    I would test what this actually do before doing with this with real data. This thing just dropped a table that was important to us. Luckily, in a test databse.
    – ooxio
    Mar 31, 2016 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.