AttributeError: module 'django.db.models' has no attribute 'CASCAD'
时间: 2023-12-22 13:30:08 浏览: 185
AttributeError: module 'tensorflow.compat.v1' has no attribute '
这个错误是由于在引用中的代码中使用了错误的外键级联选项。正确的外键级联选项是`models.CASCADE`,而不是`CASCAD`。请修改代码中的错误拼写,将`CASCAD`改为`CASCADE`,然后重新运行代码即可。
```python
# mysite/polls/models.py
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
```
阅读全文