Help us understand the problem. What is going on with this article?

modelにカラムを追加したのにmigrationファイルに追加されない現象

事象

models.pyに定義したモデルにカラムを追加した後,makemigrationを実行するもカラムが追加されない

原因

追加したカラムの末尾にカンマが存在しており正しく認識されていなかった模様

models.py
from django.db import models


class Category(models.Model):
    id = models.AutoField(primary_key=True)
    description = models.CharField(
        max_length=20
    )
    test_column1 = models.IntegerField()
    test_column2 = models.IntegerField(), # カンマがあるため反映されない

    class Meta:
        db_table = 'category'

python manage.py makemigrationsを実行すると

0001_initial.py
# Generated by Django 2.2.5 on 2019-10-21 07:51

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Category',
            fields=[
                ('id', models.AutoField(primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=20)),
                ('test_column1', models.IntegerField()),
            ],
            options={
                'db_table': 'category',
            },
        ),
    ]

たしかにtest_column2が反映されていないことが分かる.
makemigrations, migrateともに実行してもエラーや警告が発生せず原因を特定するのに時間が掛かってしまった.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした