mysql - Django: How to deal with model subclassing and IntegrityErros? -


i have in models.py

class page(models.model)     #fields  class news(page)     #no fields  class newscomment(models.model)     news = models.foreignkey(news)     name = models.charfield(max_length=128)     email = models.emailfield(max_length=75)     comment = models.textfield() 

every time trying this:

page = get_object_or_404(news, id=page_id)

and then

comment, created = newscomment.objects.get_or_create(news=page, name=name, email=email, comment=text)

i error:

(1452, 'cannot add or update child row: foreign key constraint fails (myproject_db.main_newscomment, constraint news_id_refs_page_ptr_id_5a5b8a6204eece43 foreign key (news_id) references main_news (page_ptr_id))')

what doing wrong?

(ps: using mysql innodb storage engine)

if news model has no fields should implement inheritance using a proxy model. lead simpler database schema, , simpler , faster (!) queries. eliminate problems dealing how model inheritance implemented on database level.

class page(models.model)     #fields  class news(page)     class meta:         proxy = true 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -