Django Migrations不会创建新表Store_item [已解决]

时间:2019-05-09 05:05:30

标签: django postgresql migration

当我在应用程序“商店”中为模型中名为“项”的数组字段设置错误的默认值时,我遇到了一个问题。本质上,我将array字段的默认值设置为一个单词,并且想要使用方括号,但我将其格式设置错误。

为解决此问题,因为我不能再迁移新迁移而又没有收到有关上述问题的错误,所以我决定从postgres数据库中手动删除store_item表,删除所有迁移,然后完全删除其中的array字段。项目模型。问题解决了..我无法迁移并且无法运行服务器...

新问题是,当我运行makemigrations时,它将尝试为Item创建一个名为store_item的新表,但是一旦我成功运行迁移,它就不会在数据库中实际创建该表。

# Generated by Django 2.0.8 on 2019-05-09 04:57

from django.conf import settings
import django.contrib.postgres.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Item',
            fields=[
                ('is_active', models.BooleanField(db_index=True, default=True, help_text='Designates whether this item should be treated as active. Unselect this instead of deleting data.')),
                ('created_time', models.DateTimeField(auto_now_add=True, verbose_name='created time')),
                ('modified_time', models.DateTimeField(auto_now=True, verbose_name='last modified time')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=25)),
                ('price', models.DecimalField(decimal_places=2, max_digits=6, null=True)),
                ('recipe', models.CharField(max_length=256)),
                ('ingredients', django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=10, null=True), null=True, size=8), null=True, size=8)),
                ('description', models.CharField(max_length=500, null=True)),
                ('image', models.ImageField(height_field='height_field', null=True, upload_to='', width_field='width_field')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='Created_by', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
    ]

错误

  

关系“ store_item”不存在第1行:SELECT COUNT(*)AS   “ __count”来自“ store_item”

0 个答案:

没有答案