Django makemigrations omits some fields from model

▼魔方 西西 提交于 2019-12-13 07:39:45

问题


In my django app I've created a model like that:

class Plan_miesieczny_aktualny(models.Model):
    id = models.CharField(max_length=30, primary_key=True)
    pozycja_planu = models.ForeignKey('Pozycje_planu', to_field='id')
    miesiac = models.IntegerField
    liczba = models.DecimalField
    cena = models.DecimalField
    pakiet = models.ForeignKey('Pakiet', to_field='id')
    kod_grupy = models.IntegerField(null=True)

But initial makemigrations has produced that:

    migrations.CreateModel(
        name='Plan_miesieczny_aktualny',
        fields=[
            ('id', models.CharField(max_length=30, primary_key=True, serialize=False)),
            ('kod_grupy', models.IntegerField(null=True)),
            ('pakiet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='nfz_umx.Pakiet')),
        ],
    ),

    ....

    migrations.AddField(
        model_name='plan_miesieczny_aktualny',
        name='pozycja_planu',
        field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='nfz_umx.Pozycje_planu'),
    ),

Why some fields are missing?


回答1:


You should always declare fields calling fields class constructor:

miesiac = models.IntegerField()
liczba = models.DecimalField(max_digits=5, decimal_places=2)
cena = models.DecimalField(max_digits=5, decimal_places=2)


来源:https://stackoverflow.com/questions/37276758/django-makemigrations-omits-some-fields-from-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!