The migrate in Django is invalid, and the sqlmigrate query found that the creation statements are empty. There is no solution. no, no, no. There is no information on the Internet.

problem description

in django2.0, add fields to the existing models, then migrations creates the table, uses the migrate Synchronize database, prompts "No changes detected", and then according to Baidu, Google search, according to the online method, delete the migrations folder, delete the database django_migrations field, the re-creation prompt is successful, but there are still no forms created in the database.

finally, prepare to create a new database, re-create the table in the new database, and then migrate the data to the new database. Using the above command in the new database, it is found that the table still cannot be created. Every time you are prompted to create successfully, there is still no new table created in the database.

then use sqlmigrate lookup and find that there are no sql statements to build the table. Google Baidu again, found that there is almost no information, perplexed for many days, can not be solved. I"d like to ask a question here.

clipboard.png

migrationsdjango_migrations

migrations

clipboard.png

Dec.20,2021

later found that when designing the database table, one more parameter was set in meta.

clipboard.png

class Meta:
    ***managed = False
    db_table = 'desgin'
    verbose_name = ""  -sharp 
    verbose_name_plural = ""  -sharp 
   

asterisk column of this row, after query, found that after setting this parameter, managed because Django will automatically generate mapped database tables according to the model class, if you do not want Django to do so, you can set the value of managed to False.

then suddenly enlightened, delete this field, and then execute it again. Makemigrations, successfully created the 0002 file, and after migrate, the table was successfully created in the database.

Menu