简体   繁体   中英

Django missing fields after initial makemigration

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

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?

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'

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM