Django 1054 - Unknown column in field list

I have a Django project and I did the following:

  • Added multi-column table
  • Insert some entries into db
  • Added a new column that I didn't understand what I needed
  • Made update to populate this column

When I did migrate

, everything worked fine. A new db column has been created in the table and the values ​​have been populated.

However, when I try to run my tests, I now bomb in step 2 above. When I insert, I believe it expects this field to be, even though it hasn't been created yet at this point.

What should I do?

EDIT: additional information

First I created a class, class A and did a migration to create the table. Then I ran this against my db. Then I wrote a manual migration to fill in some data that I knew would be there. I am against dB. After a while, I realized that I needed an additional field on the model. I added this field and migrated and executed over the database. Everything worked fine and I confirmed that the new column is in the database.

Now I went for tests. It tried to create a test db and got bombarded saying "1054 - Unknown column [my new column that I added to an existing table]" while trying to run the populated data script I wrote. He's probably looking at the table, noticing that a third field exists in the model but is not yet in the database, but I don't know how to do it better.

+3


source to share


3 answers


I believe this is because the migration scripts were getting called out of order due to the problem I was configuring them with. Now everything is all right.



0


source


If the new column has no default, the insert statement will wait for data to be added to that column. Can you move the data load after the second migration. (I would comment, but don't have enough reputation yet.)



0


source


This happened to me because I faked one migration (m1), created another (m2), and then tried to migrate the m2 before I had my fake initial migration (m1).

So in my case I had to migrate --fake <app name> m1

, then migrate <app name> m2

.

0


source







All Articles