How can I set the starting value for an Auto Incremented id using annotations ?
I want it to start at 250000
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
Don't know this answer is useful to users or not. But for me its giving required result (for docrtine with mysql) I had used auto increment id as normally used,
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
First time you run command to update than table will create. Than you should manually run below command to set custom initial auto increment id
ALTER TABLE users AUTO_INCREMENT=1001;
Again on running schema it will not update auto increment which is manually set. And thats it!! Its the desired result.
/**
* @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
On MySQL platform, I write that (@ORM\Table(options={"auto_increment": 12345})
) to add "AUTO_INCREMENT = 12345" to the SQL creation table. I didn't 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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With