当我运行python manage.py makemigrations myapp并检查我的迁移文件夹中的0001_initial.py文件时,我希望看到我的模型中的每个字段,但我看到的是下面的内容:
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Data',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('original_file', models.TextField(max_length=255)),
],
options={
'managed': False,
'db_table': 'acoustic_data',
},
),
migrations.CreateModel(
name='Sites',
fields=[
('site_name', models.TextField(primary_key=True, serialize=False)),
],
options={
'managed': False,
'db_table': 'site',
},
),
]
你可以看到数据模型只有'original_file'字段,而我还期待'data_id','site_id','date_recorded','time_recorded'和'average'。对于网站模型,“site_id”也缺失。我想知道为什么只有最后一个字段出现?
以下是我的models.py:
from django.db import models
# Create your models here.
class Sites(models.Model):
site_id = models.TextField(primary_key=True)
site_name = models.TextField(max_length=255)
class Meta:
managed = False # this means Django should never alter this table
db_table = 'site'
class Data(models.Model):
data_id = models.IntegerField(primary_key=True)
site_id = models.ForeignKey(Sites, db_column='site_id', to_field='site_id')
date_recorded = models.DateField('%Y-%m-%d')
time_recorded = models.TimeField('%H:%M:%S')
average = models.FloatField(null=True, blank=True, default=None)
original_file = models.TextField(max_length=255)
class Meta:
managed = False # this means Django should never alter this table
db_table = 'acoustic_data'
我还提到了这个问题Django makemigrations omists some fields from model,但它似乎对我没用。
答案 0 :(得分:1)
如果是0001版〜>你是第一次参与。
请删除并再次创建(当模型尚未完成时,您可能会进行迁移)
如果此问题仍然存在,请编辑以获取更多详细信息(控制台日志)