TypeError:收到了意外的关键字参数'model'(Django)

时间:2019-08-11 02:51:00

标签: python django

我正在创建数据迁移,以实例化数据库的多个Mineral对象。在控制台中运行python manage.py migrate时,出现错误:TypeError: Mineral() got an unexpected keyword argument 'model'

我找不到与Django提出的关键字相似的内容。是什么原因导致此错误阻止创建模型实例?

#models.py

from django.db import models

# Create your models here.
class Mineral(models.Model):
    name = models.CharField(unique=True, max_length=60, null="")
    image_filename = models.CharField(max_length=65, null="")
    image_caption = models.CharField(max_length=410, null="")
    category = models.CharField(max_length=50, null="")
    formula = models.CharField(max_length=280, null="")
    strunz_classification = models.CharField(max_length=110, null="")
    color = models.CharField(max_length=195, null="")
    crystal_system = models.CharField(max_length=130, null="")
    unit_cell = models.CharField(max_length=140, null="")
    crystal_symmetry = models.CharField(max_length=130, null="")
    cleavage = models.CharField(max_length=170, null="")
    mohs_scale_hardness = models.CharField(max_length=70, null="")
    luster = models.CharField(max_length=75, null="")
    streak = models.CharField(max_length=60, null="")
    diaphaneity = models.CharField(max_length=80, null="")
    optical_properties = models.CharField(max_length=85, null="")
    refractive_index = models.CharField(max_length=125, null="")
    crystal_habit = models.CharField(max_length=240, null="")
    specific_gravity = models.CharField(max_length=70, null="") 
    group = models.CharField(max_length=20, null="")

def __str__(self):
    return self.name
# retrieve_json.py

import json

def pull_json(file):
    with open(file, 'r') as json_file:
        data = json.load(json_file)

    return data
from django.db import migrations
import os.path

from ..data.retrieve_json import pull_json

def load_mineral_data(apps, schema_editor):

    Mineral = apps.get_model('minerals', 'Mineral')

    mineral_data = pull_json(os.path.abspath('minerals/data/minerals.json'))

    for m in mineral_data:
        Mineral.objects.create(**m)


class Migration(migrations.Migration):

    dependencies = [
        ('minerals', '0001_define_mineral'),
    ]

    operations = [
        migrations.RunPython(load_mineral_data, migrations.RunPython.noop)
    ]

0 个答案:

没有答案