Reputation: 6870
I have a django app "myapp" with this in model.py:
And in the same folder, I have a migrations
folder with an empty __init__.py
and 2 files:
from django.db import models
from django.contrib.postgres.fields import ArrayField
class Characteristic(models.Model):
name = models.CharField(max_length=200)
core = models.BooleanField(default=False)
synonyms = ArrayField(
models.CharField(max_length=200, blank=True),
size=20
)
0001_initial.py
:
from __future__ import unicode_literals
import django.contrib.postgres.fields
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='characteristics',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('synonyms', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=200), size=20)),
],
),
]
Second file:
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('myapp', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='characteristics',
name='core',
field=models.BooleanField(default=False),
),
]
However, in a view, when trying to create an instance of the model:
characteristic = Characteristic(name=attribute.decode('utf-8'), synonyms=[])
characteristic.save()
I get an error:
ProgrammingError: relation "myapp_characteristic" does not exist
I did do: python manage.py makemigrations myapp
and I have at the top of the file from myapp.models import Characteristic
Does anyone know where I'm wrong ?
Upvotes: 0
Views: 95
Reputation: 2984
Makemigrations command just creates migrations for the changes in the database. It does perform any type of modification in DB.
python manage.py migrate
above command does the actual modification in the database and create an entry in migration table. so that Django can understand which migrations are actually migrated
Upvotes: 1