TypeError: ForeignKey.__init__() missing 1 required positional argument: 'on_delete'
时间: 2023-11-06 18:04:44 浏览: 284
TypeError: _queue_reduction(): incompatible function arguments.
这个错误是因为在使用ForeignKey方法时缺少了一个必需的位置参数'on_delete'。该参数用于指定级联删除的行为,即当删除一条信息时,是否同时删除与之相关的其他信息。该参数的值通常设置为models.CASCADE。要解决这个错误,只需要在ForeignKey方法中加上on_delete参数,并将其设置为models.CASCADE即可。例如:topic = models.ForeignKey(Topic, on_delete=models.CASCADE)。这样就能正确地使用外键了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [完美解决Django2.0中models下的ForeignKey()问题](https://download.csdn.net/download/weixin_38743076/13711840)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [在创建一个新模型时 ,出现错误TypeError: ForeignKey.__init__() missing 1 required positional argument:...](https://blog.csdn.net/m0_59272048/article/details/123302559)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [model.ForeignKey() TypeError: __init__() missing 1 required positional argument: 'on_delete'](https://blog.csdn.net/weixin_43424969/article/details/84478669)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文