Reputation: 1185
I have a django blog project, and recently made changes to my local environment and so am now manually migrating to my production server. I've managed to nearly complete this, however when in psql / postgres I use the command:
\d posts_post
The foreign key field:
"Category" ( models.ForeignKey('Category', null=True, blank=True))
Is nowhere to be seen as per the terminal. I've made another migration file as such:
from __future__ import unicode_literals
from django.db import migrations, models
import mptt.fields
import django.utils.timezone
import mptt
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('posts', '0016_remove_post_category'),
]
operations = [
migrations.AddField(
model_name="Post",
name = "Category",
field = models.ForeignKey('Category', null=True, blank=True)
),
]
However when I run the migrate command it actually removes the field.
a) Why does the manager remove my field instead of adding it?
b) Why is it doing this despite apparently not existing in the first place?
Upvotes: 0
Views: 423
Reputation: 778
If you see category_id, then it's FK mapping field. You can't see a foreign key as the same name that you have given in your models.py
. It will be suffixed with _id
in database level.
But while you use django orm, you will be using only the field name that you have given in your models.py
Upvotes: 1