In doctrine2, is it possible to have an auto-increment column that is not a primary key?

In doctrine2, I have an entity that has a primary key that comes from a web service and also has an index, which should be auto-incremented.

I can install manually in mysql, but I can not do this work in doctrine2.

+4
source share
3 answers

The auto-increment limit is related to the database you are using. in Mysql, Mysql_autoincrement , it also depends on the engine you are using. Exemple:

For MyISAM and BDB tables, you can point AUTO_INCREMENT to a secondary column in an index with multiple columns. In this case, the generated value for the AUTO_INCREMENT column is calculated as

You can have general aut_increment documentation here

In general, auto_increment is reserved for a numeric field that is part of the identifier index (one or more columns are used).

Thus, this can work for mysql.

However, the auto_incriment in the doctrine seems to be only for everyone, for this @Id (primary key)

21.2.9. @GeneratedValue

Determines which strategy is used to generate the identifier for the instance variable that @Id annotates. This annotation is optional and makes sense when used in conjunction with @Id.

If this annotation is not specified using @Id, the default NONE strategy is used.

Required Attributes:

strategy: set the name of the strategy for generating the identifier. valid values ​​are AUTO, SEQUENCE, TABLE, IDENTITY, UUID, CUSTOM, and NONE. Example:

?php /** * @Id * @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id = null; 

Doctrine_auto_increment

You might want to find an arround job and post a ticket about it

+7
source

I used columnDefinition of INT AUTO_INCREMENT UNIQUE

 /** * @var integer * * @ORM\Column(type="integer", name="sequence", nullable=true, columnDefinition="INT AUTO_INCREMENT UNIQUE") */ protected $sequence = null; 

Doctrine migration kit generates

 $this->addSql('ALTER TABLE table_name_here ADD sequence INT AUTO_INCREMENT UNIQUE'); 
+11
source
 /** * @Id * @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ protected $id; 

This will work for mysql! Hope this helps!

-3
source

All Articles