Symfony, Unable to get sequence id with PostgreSQL Database
When doing Symfony development, I usually build the database schema manually through phpPgAdmin or writing my own schema file. I like propel-generate-crud in symfony, which can generate the admin form on the fly.
Previously I was having problem with PostgreSQL Database’s sequence id. When I did propel-build-model, the seq_id from Postgresql database is not sync with the model been built by symfony. To solve that, I did manual change on PostgreSQL by renaming the tablename_id_seq to tablename_seq. After I have did some testing, found a way to solve the sequence id problem.
As i mentioned previously, I usually create the schema by the phpPgAdmin or writing my own schema file instead of the one in symfony config directory which name schema.xml or schema.yml. These are the step I took to generate the admin form with propel-generate crud.
- Build database table/schema
- run symfony propel-build-schema
- run symfony propel-build-model
- run symfony propel-generate crud
After that, access to the admin form and try to insert new database, usually the transaction will fail because the system unable to detect the sequence id. Error message shown below;
Unable to get sequence id. [wrapped: Unable to fetch next sequence ID without sequence name.]
Instead of doing the manual way, alter the sequence id in postgresql database, you can fix that by doing symfony propel-build-schema xml. Symfony will generate the schema in xml format, which include postgresql sequence id name.