django 外鍵創(chuàng)建注意事項(xiàng)說明
創(chuàng)建表需要鏈接外鍵時,需要注意的事項(xiàng)。
class Book(models.Model): name=models.CharField(max_length=20) price=models.IntegerField() pub_date=models.DateField() publish=models.ForeignKey('Publish',on_delete=models.CASCADE) # 添加外鍵的時候publish 可以不加引號;如果不加引號外鍵就要寫在主表上面,否則查找不到。添加引號則是按照映射關(guān)系查找,就不用考慮先后順序。 # authors=models.ManyToManyField('Author') def __str__(self): return self.nameclass Publish(models.Model): name=models.CharField(max_length=32) city=models.CharField(max_length=32) def __str__(self): return self.name
補(bǔ)充知識:Django重寫User外鍵重復(fù)問題
python Migrate 出現(xiàn)以下錯誤
auth.User.groups: (fields.E304) Reverse accessor for ’User.groups’ clashes with reverse accessor for ’User.groups’.
HINT: Add or change a related_name argument to the definition for ’User.groups’ or ’User.groups’.
auth.User.user_permissions: (fields.E304) Reverse accessor for ’User.user_permissions’ clashes with reverse accessor for ’User.user_permissions’.
在setting里添加
AUTH_USER_MODEL = ’users.UserProfile’
即可解決問題。
以上這篇django 外鍵創(chuàng)建注意事項(xiàng)說明就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程2. jsp文件下載功能實(shí)現(xiàn)代碼3. 如何在jsp界面中插入圖片4. ASP動態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享5. 詳解瀏覽器的緩存機(jī)制6. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法7. Xml簡介_動力節(jié)點(diǎn)Java學(xué)院整理8. phpstudy apache開啟ssi使用詳解9. jsp實(shí)現(xiàn)登錄驗(yàn)證的過濾器10. JSP之表單提交get和post的區(qū)別詳解及實(shí)例
