0

在我的 django 应用程序中,我创建了一个这样的模型:

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)

但最初的迁移已经产生了:

    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'),
    ),

为什么缺少某些字段?

4

1 回答 1

4

您应该始终声明调用字段类构造函数的字段:

miesiac = models.IntegerField()
liczba = models.DecimalField(max_digits=5, decimal_places=2)
cena = models.DecimalField(max_digits=5, decimal_places=2)
于 2016-05-17T13:03:44.947 回答