1
votes

I am attempting to wrap a Doctrine model around a legacy database table in PostgreSQL that has:

    Column   |           Type           |                      Modifiers                       
 ------------+--------------------------+------------------------------------------------------
  id         | integer                  | not null default nextval('table_name_id_seq'::regclass)

If I try a mapping like:

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

Then the schema update tool gives me this:

 ALTER TABLE table_name ALTER id DROP DEFAULT;

If I try to explicitly define the default, such as:

/**
 * @ORM\Id
 * @ORM\Column(name="id", type="integer", unique=true, options={"default"="nextval('table_name_id_seq'::regclass)"})
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

Then it still gives:

ALTER TABLE table_name ALTER id SET DEFAULT nextval('table_name_id_seq'::regclass);
ALTER TABLE table_name ALTER id DROP DEFAULT;

And finally, if I try to specify the sequence manually:

/**
 * @ORM\Id
 * @ORM\Column(name="id", type="integer", unique=true)
 * @ORM\GeneratedValue(strategy="SEQUENCE")
 * @ORM\SequenceGenerator(sequenceName="table_name_id_seq", initialValue=1, allocationSize=1)
 */
private $id;

I still get the DROP DEFAULT:

ALTER TABLE table_name ALTER id DROP DEFAULT;

Is there a workaround for this problem that still allows for the use of the schema update tool? I was not able to find a Doctrine bug relating to this but it's possible I missed something. This is on the latest 2.4.X version of Doctrine running under Symfony 2.5.2.

1

1 Answers

9
votes

try

* @ORM\GeneratedValue(strategy="IDENTITY")