初始makemigration后,Django缺少字段 [英] Django missing fields after initial makemigration

查看:44
本文介绍了初始makemigration后,Django缺少字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行python manage.py makemigrations myapp并检查我的migrations文件夹中的0001_initial.py文件时,我希望能看到模型中的每个字段,但是下面是我看到的内容:

When I run python manage.py makemigrations myapp and check the 0001_initial.py file in my migrations folder, I expected to see every field in my models, however what I see is below:

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"也缺失.我想知道为什么只显示最后一个字段?

you can see that the Data model only has 'original_file' field while I was expecting also 'data_id', 'site_id', 'date_recorded', 'time_recorded' and 'average'. For the Site model 'site_id' is also missing. I am wondering why only the last field shows up?

下面是我的模型.py:

Below is my 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从模型中删除了某些字段但它似乎对我不起作用.

I also referred to this question already Django makemigrations omists some fields from model but it didn't seem to work for me.

推荐答案

如果它是0001版本〜>您是第一次进行迁移.

If it is 0001 version ~> You makemigrations for the first time.

删除再次创建(可能是您在模型尚未完成时进行迁移)

Please delete it and create again (may be you makemigrations when the models don't complete yet)

如果此问题仍然存在,请进行编辑以获取更多详细信息(控制台日志)

If this problem stay still please edit for more detail (the console log)

这篇关于初始makemigration后,Django缺少字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆