Django 1.7 migrations won't recreate a dropped table, why?

前端 未结 10 1056
挽巷
挽巷 2020-12-23 14:16

Using Django 1.7 migrations.

I accidentally dropped a table in my database. I assumed that by running migration again this would recreate the table but no, Django st

10条回答
  •  无人及你
    2020-12-23 14:54

    In my case in django 2.0.2 for recreating dropped table I needed to comment my models in myapp and then migrate with --fake and uncomment my models and migrate without --fake A little different from raul answer:

    1. Delete your migrations files in your desired app
    2. Thanks to raul answer: In the database: DELETE FROM django_migrations WHERE app = 'app_name'.
    3. comment codes in models.py and all this models usage in views, signals and etc (to prevent error).
    4. python manage.py makemigrations YOUR_APP_NAME
    5. python manage.py migrate --fake
    6. un-comment what you commented in step 3
    7. python manage.py makemigrations YOUR_APP_NAME
    8. migrate without --fake: python manage.py migrate

    This should solve some users problem.

提交回复
热议问题