创建表时候报错

Posted woshinige

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建表时候报错相关的知识,希望对你有一定的参考价值。

在创建表示出现

TypeError: __init__() missing 1 required positional argument: ‘on_delete‘错误:

表如下:

class  UserType(models.Model):
caption=models.CharField(max_length=32)

class UserInfo(models.Model):
username=models.CharField(max_length=32)
age=models.IntegerField()
user_type=models.ForeignKey(‘UserType‘) #外键
执行python manage.py makemigrations 时报错
在外键后面添加如下的代码
,on_delete=models.CASCADE,
能够解决,添加以后代码如下:
class  UserType(models.Model):
caption=models.CharField(max_length=32)

class UserInfo(models.Model):
username=models.CharField(max_length=32)
age=models.IntegerField()
user_type=models.ForeignKey(‘UserType‘,on_delete=models.CASCADE,) #外键


















以上是关于创建表时候报错的主要内容,如果未能解决你的问题,请参考以下文章

ueditor禁用编辑的时候报错:Uncaught TypeError: Cannot read property 'contentEditable' of undefined(代码片

项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde(代码片段

Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段

Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段

已解决在react+ts中 atnd 用 upload 组件报错Failed to execute ‘readAsArrayBuffer,param 1 is notof type Blob(代码片段

已解决在react+ts中 atnd 用 upload 组件报错Failed to execute ‘readAsArrayBuffer,param 1 is notof type Blob(代码片段