Django Programming error column does not exist even after running migrations

前端 未结 9 1024
南旧
南旧 2020-12-08 20:54

I run python manage.py makemigrations and I get: No changes detected Then, python manage.py migrate and I get: No migrations to apply.

9条回答
  •  执念已碎
    2020-12-08 21:23

    So, I always run into this sort of problem, so today I decided to try and work it out at the database level. Thing is, I changed a model field name which Django didn't bother reflecting in a migration file. I only found out later when I ran into problems. I later looked at the migration files and discovered there was no migration for that change. But I didn't notice because I made other changes as well, so once I saw a migration file I was happy. My advice. Create migration for each change one at a time. That way you get to see if it happened or not.

    So here's my working through it in MySQL.

    open mysql console.

    show databases; # see all my dbs. I deleted a few
    drop database ; # if needed
    use ; # the database name for your django project
    show tables; # see all tables in the database
    DESCRIBE ; # shows columns in the database
    SHOW COLUMNS FROM ; # same thing as above
    ALTER TABLE  CHANGE   ; # now I manually updated my column name
    

    If you're using postgresql, just google the corresponding commands.

提交回复
热议问题