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

Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91

1 Answers1

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.

mehmet
  • 7,720
  • 5
  • 42
  • 48
knbk
  • 52,111
  • 9
  • 124
  • 122
  • 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? – Nathan Tregillus Jun 01 '15 at 15:25
  • You'll be prompted every time you run a migration that renames or removes a model. – knbk Jun 01 '15 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? – Nathan Tregillus Jun 01 '15 at 15:31
  • sorry, last question I SWEAR! I found the documentation about --noinput, and was able to see that we ARE using it. HOWEVER, what does the system answer when I use this option? from what I understand, would the system answer yes? – Nathan Tregillus Jun 01 '15 at 15:46
  • 1
    The system is quite conservative if you use the `--noinput` option. For contenttypes, it would always answer `no`. – knbk Jun 01 '15 at 16:22
  • I have a problem: each time I run "migrate", it asks for it, even if I dont touch anything. – Olivier Pons Nov 30 '15 at 11:41
  • 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 '16 at 10:42