MySQLdb.OperationalError: and django.db.utils.OperationalError 1054, "Unknown column" after field rename in Django and MySql

20 views Asked by At

I have django app that is connected to MySql database. I have renamed the field in models.py and succesfuly ran the migration. (the name alteration is written in migrations file)

I have also manually altered the field in the MySql, so it's called the same as in models.py;

After trying to run new migrations i get MySQLdb.OperationalError: and django.db.utils.OperationalError1054, "Unknown column 'oldName' in 'mysql_tableName'" (oldName being field name before altering filed, mysql_tableName the name of the table as it is in the MySQL database)

What should I do? Why does django db connection have oldName of the field?

inspectdb shows the new field name in the output; when checking mysql, there is new name of the field, running the sql command in db (SELECT newName FROM mysql_tableName) works fine.

EDIT: Ok, so my problem i guess was, that because the Meta atribute was set to Managed = True in models.py so the app was probably trying to change the db field but couldn't find it, as i renamed it manually in the db; After I renamed the mysql field to original; the migration took place without error, the field was also renamed in the db.

0

There are 0 answers