[英]AttributeError: module 'django.db.models' has no attribute 'Models'
[英]AttributeError: module 'django.db.models' has no attribute 'BigAutoField'
所以我正在關注教科書“Python 速成班第二版”中的 Django 項目,我正在為那些知道的人進入映射 URLS 部分,當我嘗試我的系統似乎無法運行服務器時,我遇到了以下問題錯誤:AttributeError:模塊“django.db.models”沒有屬性“BigAutoField”
如果有人可以提供幫助,那就太好了,已經謝謝了。 我是 django 的新手,正在嘗試解決它,但我真的不知道在什么地方或在哪里可以找到錯誤..
在我添加兩個 urls.py 之前它實際上工作正常:
from django.urls import path, include
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('learning_logs.urls'), name='learning_logs'),
]
和
"""Defines url patterns for learning_logs."""
from django.urls import path
from . import views
app_name = 'learning_logs'
urlpatterns = [
# Home page.
path('', views.index, name='index'),
]
models.py 是
from django.db import models
# Create your models here.
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, on_delete=models.CASCADE)
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"""
if len(self.text) >= 50:
return f"{self.text[:50]}..."
else:
return "..."
這是您必須更改的版本。 Django 1.8 沒有BigAutoField
。
這是 url 到 Django 1.8 文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.