请帮忙
我正在使用django 2.1.4设计博客应用程序。实际上,我遵循的是使用django 1.8的安东尼奥·梅尔(antonio mele)的“ Django示例”一书中的说明。 但是,在创建应用程序并添加博客模型之后,我尝试为新模型应用迁移,但收到此错误消息。
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\public\django\my_env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_c
ommand_line
utility.execute()
File "C:\Users\public\django\my_env\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\public\django\my_env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\public\django\my_env\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\public\django\my_env\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\public\django\my_env\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\public\django\mysite\blog\models.py", line 14, in <module>
related_name='blog_posts')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
@伊曼纽尔..这是models.py文件上的完整代码
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250,
unique_for_date='publish')
author = models.ForeignKey(User,
related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,
choices=STATUS_CHOICES,
default='draft')
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title