我最近开始了django项目,但是访问我最近添加的sqlite3数据库时遇到了问题。将新数据库插入settings.py后,我运行了d
。这给了我复制粘贴到models.py中的文件。从那里运行python manage.py inspectdb --database 'football'
,它给了我这个错误:
makemigrations
从那里我在需要的地方将null更改为false,然后重新运行SystemCheckError: System check identified some issues:
ERRORS:
teambuilder.Countries.country_id: (fields.E007) Primary keys must not have null=True.
HINT: Set null=False on the field, or remove primary_key=True argument.
teambuilder.Playertransferhistory: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.
teambuilder.Teams.team_id: (fields.E007) Primary keys must not have null=True.
HINT: Set null=False on the field, or remove primary_key=True argument.
(venv) Jacks-MBP:SportWebsite Tilley$ python manage.py makemigrations
SystemCheckError: System check identified some issues:
ERRORS:
teambuilder.Playertransferhistory.id: (fields.E007) Primary keys must not have null=True.
HINT: Set null=False on the field, or remove primary_key=True argument.
这给了我这个:
makemigrations
后跟Migrations for 'teambuilder':
teambuilder/migrations/0001_initial.py
- Create model Countries
- Create model LeagueGames
- Create model Leagues
- Create model Playerinfo
- Create model Playertransferhistory
- Create model Teams
,其输出:
migrate
然后我运行Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, sites, teambuilder
Running migrations:
No migrations to apply.
并输入以下命令:
python manage.py shell
向我展示了这堵红墙:
from teambuilder.models import *
Leagues.objects.all()
我知道该表确实存在,但是我不明白为什么会收到此错误。我在SO上看到过类似的问题,但是没有一个解决方案可以解决我的问题。任何帮助将不胜感激。