Hello All,

I have a django model class defined as:


class Test(models.Model):
   id=AutoField(primary_key=True)
   name = models.CharField(max_length=45, null=False)
   description = models.CharField(max_length=200, null=True)
   uuid = models.CharField(max_length=250)
   class Meta:
       managed = False
    db_table ="test"

Where, 
uuid is auto generated using a mysql trigger. 

Mysql Trigger looks like:
DROP TRIGGER IF EXISTS `test_uuid`//
CREATE TRIGGER `test_uuid` BEFORE INSERT ON` test
`
FOR EACH ROW begin if (new.uuid is  null or new.uuid = '') then set new.uuid 
= (select uuid());end if; end
//
This trigger is added at the db level.

i.e., any new insert in 'test' table would generate the value for uuid 
column.
and insert works fine for this model from the code.

Issue is, when I try to access the uuid after I have performed the save(), 
I am getting null.

row = Test(name=in_data['name'],
                  description=in_data['description'],
           )
row.save()  # This creates a row with id, name, description and uuid (auto 
generated by the pre insert rigger)
print(row.id)   # Prints id
print(row.uuid) # Prints u' '




Any idea as to what may be going on?
Why row.uuid is coming as empty from the code though the uuid is clearly 
generated in the db table.


Any pointers on this would be highly appreciated.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c46aa030-f3e0-4f0f-a671-2989e8cfcc52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to