我目前正在从Eric Matthes的一本名为Python Crash Course的书中做一些项目。目前,我正在做实验19.1,我必须使用以前的代码来创建一个Django项目,同时改变他自己的一些代码,但遇到了问题。 每次我想运行这个命令
>>>python manage.py makemigration blogs
作为回报,我得到了这段代码
TypeError: init ()缺少1个必需的位置参数: ' on_delete'
他原来的models.py代码:
from django.db import models
class Topic(models.Model):
"""A topic the user is learning about."""
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""Return a string representation of the model."""
return self.text
class Entry(models.Model):
"""Something specific learned about a topic."""
topic = models.ForeignKey(Topic)
text = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name_plural = 'entries'
def __str__(self):
"""Return a string representation of the model."""
return self.text[:50] + "..."
和我目前的代码:
from django.db import models
# Create your models here.
class BlogPost(models.Model):
title = models.CharField(max_length=200)
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""Return a string representation of the model."""
return self.text
class Post(models.Model):
"""SThe post"""
topic = models.ForeignKey(BlogPost)
text = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name_plural = 'posts'
def __str__(self):
if len(self.text) >= 50:
"""Return a string represerntation of the model"""
return self.text[:50] + "..."
else:
return self.text
老实说,我不知道为什么我会收到这个错误代码我会检查一下我是否搞砸了但我找不到任何东西。有没有人知道?