Reputation: 1362
I'm using doctrine with a postgres database alongside with FOSUserBundle. For some reason, every time I try to run doctrine:schema:update
, it attempts to create the user table, even though it already exists.
I've had to set the schema to the user table to public in the entity because FOS would error otherwise about a missing schema. Removing this annotation from the entity will stop it from attempting to recreate the table however.
The entity is defined as follows:
<?php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="user", schema="public")
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*/
class User extends BaseUser {
...
}
and the query that doctrine keeps trying to execute with schema="public"
set on the entity is:
CREATE SEQUENCE public.user_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE public."user" (id INT NOT NULL, username VARCHAR(180) NOT NULL, username_canonical VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) NOT NULL, enabled BOOLEAN NOT NULL, salt VARCHAR(255) DEFAULT NULL, password VARCHAR(255) NOT NULL, last_login TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, password_requested_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, roles TEXT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE UNIQUE INDEX UNIQ_327C5DE792FC23A8 ON public."user" (username_canonical);
CREATE UNIQUE INDEX UNIQ_327C5DE7A0D96FBF ON public."user" (email_canonical);
CREATE UNIQUE INDEX UNIQ_327C5DE7C05FB297 ON public."user" (confirmation_token);
If I add the schema="public"
tag to any of my other entities, they exhibit the same behaviour, however they work fine without it. It's just the User entity that doesn't work with FOSUserBundle with the following message when trying to create a user for example:
SQLSTATE[42703]: Undefined column: 7 ERROR: column t0.username does not exist
LINE 1: SELECT t0.username AS username_1, t0.username_canonical AS u...
Upvotes: 0
Views: 804
Reputation: 532
This is a bug in Doctrine when used with Postgres. I have this problem with Migrations all the time. I just remove the offending line and all is good. @Enumus is correct and you have to back-tick your annotation.
/**
* User
*
* @ORM\Table(name="
user")
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*
*/
Upvotes: 0
Reputation: 66
Checking the documentation can be found...
user is a reserved keyword in the SQL standard. If you need to use reserved words, surround them with backticks, e.g. @ORM\Table(name="`user`")
Could it be your problem?
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html#a-doctrine-orm-user-class
Upvotes: 1