0

I'm currently trying to update my Django models to incorporate some new functionality but after runnning "makemigrations", the console output makes me worried I'm going to overwrite other tables in the database.

Essentially, in my models.py, I have 8 models. One is entirely new, one is merely modified. I want to migrate these changes to the database so I run "makemigrations". A migration's file is created (I note there are no others whatsoever - presumably the colleague who created these originally has deleted them for whatever reason). The console output is:

- Create model ModelNew
- Create model ModelDontTouch
- Create model ModelDontTouch
- Create model ModelDontTouch
- Create model ModelDontTouch
- Create model ModelDontTouch
- Create model ModelDontTouch
- Create model ModelUpdated

Why does it say create model? Is it because, as far as Django knows, this is the first migration ever performed? Or does it plan on overwriting all those other tables (which would kill our app completely and result in a very terrible day)?

I also notice some models have specified

db_table = 'some_table'
db_tablespace = 'sometable'

others, just, db_tablespace = 'sometable'

others, nothing at all. Anyone have any thoughts on this?

Rob
  • 89
  • 1
  • 1
  • 8

1 Answers1

2

Django doesn't interrogate the database itself when making migrations; it builds up a graph based on previous migrations and the current state of the models. So if there are no previous migrations Django will create them from scratch. This won't overwrite your tables, but it won't actually work either, as it will attempt to create them and the database will refuse.

One option would be to temporarily revert your changes and run makemigrations again to get back to the right starting point, then run that migration with --fake-initial to mark it as applied without actually doing it, then reapply your changes and run makemigrations again.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Is this command supported in Django 1.7? Both "makemigrations --fake my_app" and "makemigrations --fake-initial my_app" doesn't seem to work. – Rob Aug 19 '16 at 10:06