This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » [SQLITE] Primary keys are never defined as AUTOINCREMENT
icon4.gif  [SQLITE] Primary keys are never defined as AUTOINCREMENT [message #67245] Wed, 10 December 2008 02:32 Go to next message
Riccardo  is currently offline Riccardo
Messages: 26
Registered: December 2008
Location: Trento, Italy
Junior Member
If you are using SQLite, you should be aware that primary key ID values of deleted records can get reused for newly-inserted records, unless you specify the AUTOINCREMENT keyword in the column definition. This is explained in more detail on this page of the SQLite site.

Propel 1.3, which Symfony uses to translate your schema.yml file into SQL statements, will never use the AUTOINCREMENT keyword in a SQLite database, even if you explicitly specify so.

This is an issue with Propel rather than with Symfony itself; nonetheless I thought it might be useful to report it here, in case someone ever uses the blessed Search link. Razz
icon3.gif  Quick and dirty workaround [message #67276 is a reply to message #67245 ] Wed, 10 December 2008 10:47 Go to previous messageGo to next message
Riccardo  is currently offline Riccardo
Messages: 26
Registered: December 2008
Location: Trento, Italy
Junior Member
For people who, like me, need their primary key IDs to never be re-used, here's a quick and dirty workaround.

Modify <symfony_dir> /lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/clas ses/propel/engine/platform/SqlitePlatform.php, replacing line #56
		return "PRIMARY KEY";
with this
		return "PRIMARY KEY AUTOINCREMENT";


Note that this will make all your primary keys AUTOINCREMENT. Unfortunately, being able to specify which of them should be AUTOINCREMENT and which should not requires some more tweaking and I (still Wink) don't know Propel well enough for that.
Re: [SQLITE] Primary keys are never defined as AUTOINCREMENT [message #67360 is a reply to message #67245 ] Wed, 10 December 2008 22:21 Go to previous messageGo to next message
xplo  is currently offline xplo
Messages: 428
Registered: September 2008
Faithful Member
did u try to create your model directly from a xml file ?
sometime the yml -> xml convertion fail without any warning and just delete some attributes/field

[Updated on: Wed, 10 December 2008 22:21]

Re: [SQLITE] Primary keys are never defined as AUTOINCREMENT [message #67375 is a reply to message #67360 ] Thu, 11 December 2008 00:31 Go to previous message
Riccardo  is currently offline Riccardo
Messages: 26
Registered: December 2008
Location: Trento, Italy
Junior Member
xplo wrote on Wed, 10 December 2008 22:21

did u try to create your model directly from a xml file ?
sometime the yml -> xml convertion fail without any warning and just delete some attributes/field

Shocked OMG! Thanks for the heads-up.

Anyway that is not the problem; it really is a Propel issue. There appears to be some confusion in the Propel generator between primary keys and auto-incrementing fields, at least for SQLite.
Previous Topic:symfony 1.2 - Defect in forms framework or not?
Next Topic:[Solved] build-model messing up mysql's longtext
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software