Initial Doctrine Dock @ORM \ GeneratedValue

How to set initial value for Auto Incremented id using annotations?

I want it to start with 250,000

/** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ protected $id; 
+4
source share
3 answers
 /** * @ORM\Id * @ORM\GeneratedValue(strategy="SEQUENCE") * @ORM\SequenceGenerator(sequenceName="id", initialValue=250000) * @ORM\Column(type="integer") */ protected $id; 

http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html

+10
source

I don't know if this answer is useful to users or not. But for me its providing the desired result (for docrtine with mysql) I used auto increment id, as usual,

 /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; 

The first time you run the command to update, than the table will create. Then you must manually execute the command below to set a custom auto increment id

 ALTER TABLE users AUTO_INCREMENT=1001; 

Again, when starting the circuit, it will not automatically update the increment, which is set manually. That's all!! His desired result.

+1
source

On the MySQL platform, I write this ( @ORM\Table(options={"auto_increment": 12345}) ) to add "AUTO_INCREMENT = 12345" to the SQL creation table. I did not use @ORM\SequenceGenerator :

 /* * @ORM\Table(options={"auto_increment": 12345}) */ class MyEntity { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; // Others properties } 

And in the migration file:

  $this->addSql('CREATE TABLE my_entity (id INT AUTO_INCREMENT NOT NULL, ...) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB AUTO_INCREMENT = 12345'); 
0
source

Source: https://habr.com/ru/post/900860/


All Articles