Skip to content
Advertisement

Django change wrong column name in DB

in my Database (psql) I’ve got a table named offers_offer and inside that there is an column named offer_name, which is wrong, because it should actually be just name. I don’t know why it has this name, but due to this I can’t load any fixtures or create a new object, because I always receive the error that name wasn’t found (obviously).

Now my model looks like this:

JavaScript

and my ONLY initial migration looks like this:

JavaScript

So I don’t really know why it’s named offer_name in my db, while this was created to have name as field name.

Anyway I tried to fix that by making a new migration like:

JavaScript

But if I do that, I just get a FieldDoesNotExist Error which states me that django.core.exceptions.FieldDoesNotExist: Offer has no field named 'offer_name'

So does someone know a good way to fix that?

Advertisement

Answer

You could change the model to accomodate for your custom column with the db_column argument like so:

JavaScript

To elaborate a little bit more: The db_colum parameter can be used with every default django field. When it is used django disregards it`s default naming scheme and just looks up whatever name you passed.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement