D:\TOOL\PycharmProjects\python3\BS\h3>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "D:\Program Files\python3.6\lib\site-packages\django\core\management__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:\Program Files\python3.6\lib\site-packages\django\core\management__init.py", line 347, in execute
django.setup()
File "D:\Program Files\python3.6\lib\site-packages\django\init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\Program Files\python3.6\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "D:\Program Files\python3.6\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "D:\Program Files\python3.6\lib\importlib\init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
File "
File "
File "
File "
File "
File "D:\TOOL\PycharmProjects\python3\BS\h3\booktest\models.py", line 11, in
class HeroInfo(models.Model):
File "D:\TOOL\PycharmProjects\python3\BS\h3\booktest\models.py", line 15, in HeroInfo
hbook = models.ForeignKey(BookInfo)
**TypeError: init() missing 1 required positional argument: 'on_delete'
創(chuàng)新互聯(lián)網(wǎng)站建設公司,提供成都網(wǎng)站制作、成都網(wǎng)站設計、外貿(mào)營銷網(wǎng)站建設,網(wǎng)頁設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;可快速的進行網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,是專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
**
在django2.0后,定義外鍵和一對一關(guān)系的時候需要加on_delete選項,此參數(shù)為了避免兩個表里的數(shù)據(jù)不一致問題,不然會報錯:
TypeError: init() missing 1 required positional argument: 'on_delete'
解決方案:
class BookInfo(models.Model):
btitle = models.CharField(max_length=20)
bpub_date = models.DateTimeField()
class HeroInfo(models.Model):
hname = models.CharField(max_length=20)
hgender = models.BooleanField()
hcontent = models.CharField(max_length=100)
hbook = models.ForeignKey('BookInfo', on_delete=models.CASCADE)
https://www.cnblogs.com/phyger/p/8035253.html