我正在尝试使用“ Djongo Documentation(Array Model Field)”或
所示的“数组模型字段”(djongo)添加数据from djongo import models
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
class Meta:
abstract = True
class MetaData(models.Model):
pub_date = models.DateField()
mod_date = models.DateField()
n_pingbacks = models.IntegerField()
rating = models.IntegerField()
class Meta:
abstract = True
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
class Meta:
abstract = True
def __str__(self):
return self.name
class Entry(models.Model):
blog = models.EmbeddedModelField(
model_container=Blog,
)
meta_data = models.EmbeddedModelField(
model_container=MetaData,
)
headline = models.CharField(max_length=255)
body_text = models.TextField()
authors = models.ArrayModelField(
model_container=Author,
)
n_comments = models.IntegerField()
def __str__(self):
return self.headline
添加到admin.py中,用于在管理面板中注册模型
from django.contrib import admin
from .models import Entry
admin.site.register(Entry)
当我尝试通过http://localhost:8000/admin/添加数据时,出现了MigrationError ...
我的错误在哪里?我不明白什么?
答案 0 :(得分:0)
我是个笨蛋。对不起更新模型后,我没有“ makemigration”。
因此,我做了以下工作: 1.更新模型后,我执行了“ python manage.py makemigrations”并打开了电源。
答案 1 :(得分:0)
您应该在所有模型上使用 models.ObjectIdField(),以避免调用django迁移。
示例:
class Author(models.Model):
_id = models.ObjectIdField()
name = models.CharField(max_length=200)
email = models.EmailField()
class Meta:
abstract = True
def __str__(self):
return self.name
中查看更多