On Jul 3, 6:13 am, Wanpeng <wanpeng.y...@gmail.com> wrote: > Hello, > I am writing my first app in Django. I already have existing > tables/sequences/triggers in Oracle. so I used "inspectdb" to generate the > models for django. Here's one model for example: > > class Instructors(models.Model): > > > > > instructorid = models.IntegerField(db_column='INSTRUCTORID', > > primary_key=True) # Field name made lowercase. > > instructor_name = models.CharField(max_length=50, > > db_column='INSTRUCTOR_NAME', blank=True) # Field name made lowercase. > > instructor_email = models.CharField(max_length=255, > > db_column='INSTRUCTOR_EMAIL', blank=True) # Field name made lowercase. > > comments = models.CharField(max_length=255, db_column='COMMENTS', > > blank=True) # Field name made lowercase. > > fingerprint = models.CharField(max_length=8, db_column='FINGERPRINT', > > blank=True) # Field name made lowercase. > > timestamp = models.DateField(null=True, db_column='TIMESTAMP', > > blank=True) # Field name made lowercase. > > > def __unicode__(self): > > return self.instructor_name > > class Meta: > > db_table = u'INSTRUCTORS' > > After "syncdb", here's what I do in the shell: > > >>>from mysite.assignments.models import Instructors > >>>p = Instructors(instructor_ name="John",instructor_email = " > jo...@email.com <wanpeng.y...@gmail.com>") > >>>p.save() > > I already have a trigger in oracle to insert the instructorid, the > fingerprint and timestamp. However, when I type: > > >>>p.instructorid > > It returns null while it should return a new instructorid. If I change the > model type of instructorid to AutoField, I get the 'Cannot find sequence' > error when using p.save() , but I do have the sequence and trigger. > > I tried to create a new model in django and let django create the table for > me in oracle. I don't have the same problem as with the existing tables. > > So how can I let django know 'I already have sequences and triggers, use > them!' ? > > Thank you.
Hi Wanpeng, Unfortunately, the Oracle backend doesn't currently offer a way to specify an alternative name for the sequence. However, in Django 1.1 we have changed the way AutoField values are retrieved to use a "RETURNING" clause, which in addition to being more efficient does not require knowledge of the sequence name. I would suggest upgrading to the latest trunk version if possible. If upgrading is not an option, then I suggest creating a synonym for the sequence with the name Django expects for the sequence. This is normally the name of the table plus "_SQ", unless that would be longer than the allowed 30 characters. Hope this helps, Ian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---