Re: Problem when inserting into a table with a MySQL auto_increment primary key
On Jul 18, 6:14 pm, Nis Jørgensen <[EMAIL PROTECTED]> wrote: > AnaReis skrev:> Hi all, > > I have a problem when inserting a register into this table that I'm > > working with. > > This table belongs to a MySQL database and the storage engine is > > MyISAM. The database that I'm using is a legacy database and I can't > > change it in any way. > > When I insert a register into the table it's MySQL who generates the > > primary key for me. Which means that I fill all the required table > > fields and leave the primary key field empty for MySQL to fill when I > > insert the record. The problem is, since the ".save()" method doesn't > > return any value there is no way for me to give any confirmation for > > the user if the register was inserted or not. > > Have you added the primary key to the model, like this: > > my_legacy_id = AutoField() > > If you do, I believe you will be able to read the value of the field > after calling .save(). > At least you can with the standard id field when using postgresql. > > Nis Hi Thanks for your help! I had put the AutoField() part but forgot to add the "_id" in the end of the field, that's why it wasn't working. Thanks again! :) Ana --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem when inserting into a table with a MySQL auto_increment primary key
AnaReis skrev: > Hi all, > I have a problem when inserting a register into this table that I'm > working with. > This table belongs to a MySQL database and the storage engine is > MyISAM. The database that I'm using is a legacy database and I can't > change it in any way. > When I insert a register into the table it's MySQL who generates the > primary key for me. Which means that I fill all the required table > fields and leave the primary key field empty for MySQL to fill when I > insert the record. The problem is, since the ".save()" method doesn't > return any value there is no way for me to give any confirmation for > the user if the register was inserted or not. Have you added the primary key to the model, like this: my_legacy_id = AutoField() If you do, I believe you will be able to read the value of the field after calling .save(). At least you can with the standard id field when using postgresql. Nis --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem when inserting into a table with a MySQL auto_increment primary key
If there's a problem, it will raise an exception, so you won't just slide past invisibly. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem when inserting into a table with a MySQL auto_increment primary key
Hi all, I have a problem when inserting a register into this table that I'm working with. This table belongs to a MySQL database and the storage engine is MyISAM. The database that I'm using is a legacy database and I can't change it in any way. When I insert a register into the table it's MySQL who generates the primary key for me. Which means that I fill all the required table fields and leave the primary key field empty for MySQL to fill when I insert the record. The problem is, since the ".save()" method doesn't return any value there is no way for me to give any confirmation for the user if the register was inserted or not. The only way to check if the new record was inserted is to go to the table and check if the register is there or not. Is there any way to go around this? I thought, since this is a MyISAM table, I could get the last inserted record but I still have no guaranty that the last record was the one inserted by the user since there can be two equal lines in the table with the same information but with a different primary key... How do I know if the last record was inserted by the user (which means the insert was successful) or if it was already there before and there was a problem with this last insert? Ana --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---