开发者

Django: Would object creation involving FK still work when the 2 tables involved are in different databases?

开发者 https://www.devze.com 2023-02-20 11:35 出处:网络
I have a Django model: class Note(models.Model) : text = models.TextField() owner = models.ForeignKey(User)

I have a Django model:

class Note(models.Model) : 
    text = models.TextField() 
    owner = models.ForeignKey(User) 

If Note and User are located on different da开发者_C百科tabases, would the following still work?

note = Note(text='hello world', owner=request.user) 

I understand that join will not work across databases, but will creating object instances using FK like above still work?

Thanks.


Django does not support cross-database relations, as stated in their documentation: http://docs.djangoproject.com/en/1.3/topics/db/multi-db/#cross-database-relations

So no, your snippet won't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消