waliwali / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

Error in models.ForeignKey('self') #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am running:

Django 1.2.5
ibm-db 1.0.3
ibm-db-django 1.0.1

the ibm_db modules were downloaded from svn

I have a model as follows (models.py)

class Section(models.Model):
  name = models.CharField("Name", blank=True, null=False, max_length=100)
  description = models.TextField("Description", blank=True, null=False)

  def __unicode__(self):
    return self.name

class SubSection(models.Model):
  section = models.ForeignKey(Section)
  parent_subsection = models.ForeignKey('SubSection', null=True, blank=True)
  name = models.CharField("Name", blank=True, null=False, max_length=100)
  description = models.TextField("Description", blank=True, null=False)

  def __unicode__(self):
    return self.name

When running python manage.py reset <app_name> I get the following error.

 The full error: Statement Execute Failed: [IBM][CLI Driver][DB2/AIX64] SQL0204N  "PARENT_SUBSECTION_ID_REFS_ID_D67070D" is an undefined name.  SQLSTATE=42704 SQLCODE=-204

I have tried this in another project that is running mysql as the db backend 
and it works perfectly.

The idea is to have a Section that can have multiple SubSections.

And each SubSection can also have child SubSections.

This would be similar to the table of contents in a book.

Chapter1               <Section>
---Django and DB2      <SubSection>
------Getting Started  <SubSeciton>
------Installation     <SubSection>
------Configuration    <SubSeciton>

Any ideas on what i'm doing wrong here?

Original issue reported on code.google.com by mi...@sturge.ca on 8 Mar 2011 at 6:29

GoogleCodeExporter commented 9 years ago
Sorry I made a small mistake there. Take note that the error is surrounding the 
SubSection class in: 

parent_subsection = models.ForeignKey('SubSection', null=True, blank=True) 

This will produce the same error if 'self' is used (which is recommended in the 
docs)

parent_subsection = models.ForeignKey('self', null=True, blank=True)

Original comment by mi...@sturge.ca on 8 Mar 2011 at 6:32

GoogleCodeExporter commented 9 years ago
Could you please check this with a new database.
Is any error comes at the 1st run of reset command also?

Please provide me the db2level of DB2, and the system information like on which 
platform your application is running and database resides on which platform.

Original comment by rahul.pr...@in.ibm.com on 14 Mar 2011 at 4:57

GoogleCodeExporter commented 9 years ago
I have tried to reproduce it on Linux and Window, but for these platform 
"reset" goes fine for your specified models.

Currently i didn't have AIX machine so, i haven't check it on AIX. Once i get 
AIX machine i will try on it also.

By looking into ERROR message, it looks like 
"PARENT_SUBSECTION_ID_REFS_ID_D67070D" FKey constraint didn't present on your 
existing "PARENT_SUBSECTION" table.
It may happens due to some silent error occurs, when you first time issued 
"reset" command and due to this "PARENT_SUBSECTION_ID_REFS_ID_D67070D" haven't 
created.

Please check the availability of this constraint.

If possible then try to run it on Linux/Window and let us know about error 
message.

Thanks,
Rahul Priyadarshi

Original comment by rahul.pr...@in.ibm.com on 14 Mar 2011 at 12:08

GoogleCodeExporter commented 9 years ago
I also tried to reproduce it on AIX, but i didn't get any error.

Please let me know if you are still getting the error or, is it already 
resolved. 

Original comment by rahul.pr...@in.ibm.com on 16 Mar 2011 at 10:09

GoogleCodeExporter commented 9 years ago
I found that manually deleting the tables in question resolved the issue for 
me. So running a "DROP TABLE <TABLENAME>" on each table in the model. Then 
running "python manage.py syncdb" to create them again. 

This is a strange error that is not reproducible 100% of the time, but when I 
get it now at least I have a workaround

Original comment by mi...@sturge.ca on 16 Mar 2011 at 11:32

GoogleCodeExporter commented 9 years ago

Original comment by rahul.pr...@in.ibm.com on 23 Mar 2011 at 12:34