Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django Python-迁移后删除的属性出现SQLDecodeError_Python_Django - Fatal编程技术网

Django Python-迁移后删除的属性出现SQLDecodeError

Django Python-迁移后删除的属性出现SQLDecodeError,python,django,Python,Django,我目前正在将Django2.2与Djongo1.2.38一起使用,在更改模型并运行迁移后,遇到了SQLDecodeError-DuplicateKey 我有一个模型,Project,它有一个名为customer\u-po的属性 我删除了这个属性,改变了一堆属性,并进行了迁移/应用了迁移 我可以从这行迁移的输出中看到: -从项目中删除现场客户订单 我应用了我的迁移,它是成功的 我创建了一个新的项目对象,当我要创建第二个项目对象时,遇到以下错误: FAILED SQL: INSERT INTO "c

我目前正在将Django2.2与Djongo1.2.38一起使用,在更改模型并运行迁移后,遇到了SQLDecodeError-DuplicateKey

我有一个模型,
Project
,它有一个名为
customer\u-po
的属性

我删除了这个属性,改变了一堆属性,并进行了迁移/应用了迁移

我可以从这行迁移的输出中看到:

-从项目中删除现场客户订单

我应用了我的迁移,它是成功的

我创建了一个新的项目对象,当我要创建第二个项目对象时,遇到以下错误:

FAILED SQL: INSERT INTO "crud_project" ("id", "project_number", "purchase_order", "quotation_number", "client_name", "project_name", "project_owner_id", "project_manager_id") VALUES (%(0)s, %(1)s, %(2)s, %(3)s, %(4)s, %(5)s, %(6)s, %(7)s)

Params: (UUID('eb7184ee-cc0c-4765-a04c-455a2a70af15'), '123', '12345', '321312', 'Hello', 'Ads', UUID('30f86ee3-e1b7-4820-a39e-c996a1799254'), UUID('c29f869a-e629-46b3-9cc6-cace7de1b987'))

Pymongo error: 
{'writeErrors': 
  [{'index': 0, 'code': 11000, 'keyPattern': {'customer_po': 1}, 
  'keyValue': {'customer_po': None}, 
  'errmsg': 'E11000 duplicate key error collection: psm.crud_project index: customer_po_1 dup key: { customer_po: null }', 'op': {'id': UUID('eb7184ee-cc0c-4765-a04c-455a2a70af15'), 'project_number': '123', 'purchase_order': '12345', 'quotation_number': '321312', 'client_name': 'Hello', 'project_name': 'Ads', 'project_owner_id': UUID('30f86ee3-e1b7-4820-a39e-c996a1799254'), 'project_manager_id': UUID('c29f869a-e629-46b3-9cc6-cace7de1b987'), '_id': ObjectId('5ed7c79ddfacbb6c0315927a')}}], 'writeConcernErrors': [], 'nInserted': 0, 'nUpserted': 0, 'nMatched': 0, 'nModified': 0, 'nRemoved': 0, 'upserted': []}
即使属性不在参数中,或者不再在模型中,我也会得到一个复制键的错误

这是否与在
项目
集合上创建的索引有关,该索引仍然具有旧的属性名称

谢谢

编辑:我的迁移文件

# Generated by Django 2.2 on 2020-06-03 15:10

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('crud', '0013_auto_20200519_1437'),
    ]

    operations = [
        migrations.RenameField(
            model_name='project',
            old_name='customer_project_name',
            new_name='project_name',
        ),
        migrations.RemoveField(
            model_name='project',
            name='customer_billing_manager',
        ),
        migrations.RemoveField(
            model_name='project',
            name='customer_name',
        ),
        migrations.RemoveField(
            model_name='project',
            name='customer_po',
        ),
        migrations.RemoveField(
            model_name='project',
            name='customer_project_team_name',
        ),
        migrations.AddField(
            model_name='project',
            name='client_name',
            field=models.CharField(blank=True, max_length=30),
        ),
        migrations.AddField(
            model_name='project',
            name='project_manager',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='managed_projects', to='crud.Manager'),
        ),
        migrations.AddField(
            model_name='project',
            name='project_number',
            field=models.CharField(blank=True, max_length=30, unique=True),
        ),
        migrations.AddField(
            model_name='project',
            name='project_owner',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owned_projects', to='crud.Manager'),
        ),
        migrations.AddField(
            model_name='project',
            name='purchase_order',
            field=models.CharField(blank=True, max_length=50, unique=True),
        ),
        migrations.AddField(
            model_name='project',
            name='quotation_number',
            field=models.CharField(blank=True, max_length=30, unique=True),
        ),
    ]

我通过删除索引
customer\u po\u 1
解决了这个问题

我不完全确定发生了什么,但我感觉这个字段有两个索引,
customer\u po
customer\u po
。当我应用迁移时,其中一个被删除了,但另一个没有


以上完全是一种预感,并不完全确定发生了什么

迁移文件的外观如何,可能是djongo的问题,您可以手动编写查询来删除列,如果没有mysql,为什么会将其标记为mysql错误?抱歉,删除该标记是一个意外。现在将添加我的迁移文件。@iklinac在我的数据库中的
\uuuu schema\uuuuu
集合下查看,模型尚未更新以匹配我的最新迁移../manage showmigrations--list,它是否显示为已迁移,您可以通过从django_迁移表[X]0014\u auto\u 20200603\u 1510中删除它来重试。