Django 1.7 - “No migrations to apply” when run migrate after makemigrations

后端 未结 15 1550
离开以前
离开以前 2020-11-28 20:46

I use Django1.7 with Mezzanine. I create simple profile (according to Mezzanine documentation) stored in separate app \"profiles\":

class RoadmapProfile(mode         


        
15条回答
  •  独厮守ぢ
    2020-11-28 21:41

    The problem here are fake migrations somewhere. Basically in your database the table created from your model doesn't exist, tho somewhere in time that table existed before, due an old update o whatever it may be. The problem is that django already made those migrations so the tables MUST exist for hence overlooking migrations but getting error "table_doesnt_exist" in Admin.

    Solution:

    1.- Make sure to save any data from that model.

    2.- Access your database and run this query.

     SELECT * FROM django_migrations;
    

    3.- Get the id from the list generated from the query. These are migrations that Django has migrated so far, hence TABLES MUST EXIST. In your case I'd look for a row named roadmapprofile, due this is the name of your model.

    4.- Now lets delete this row from this table using the ids,

     DELETE FROM django_migrations where django_migrations.id in (value_id1, value_id2 ... value_idN);
    

    Replace value_id1 and value_id2 with respective ids. It could be only one or many so don't worry if you don't see more than 1 id, what this means is that only one model exists under the current app.

    5.- Migrate app to zero

     manage.py migrate  zero
    

    6.- Delete all migrations files within the app migrations folder

    7.- Create Migrations

     manage.py makemigrations
    

    8.- Once you delete these registries and run manage.py migrate; Django will be forced to run migrations for these models due "MIGRATIONS WON'T EXIST" for these models.

     manage.py migrate
    

    That's it. You shouldn't have any problems following these instructions. By the way, you shouldn't loose any data from other models due you're only migrating and updating tables related to these specific models.

提交回复
热议问题