2014-02-08 15 views
1

我正在學習symfony 2。 之前,我在使用MySQL,但我想嘗試Symfony 2和教義的力量。所以我想從MySQL切換到PostgreSQL。 我有一切安裝好了......數據庫是用doctrine命令創建的,轉儲也是成功的......當我想從主頁註冊一個新用戶。我有這個例外:Symfony 2 - PostgreSQL - SQLSTATE [42809]:錯誤的對象類型:7錯誤:列符號

An exception occurred while executing 'SELECT t0.username AS username1, 
t0.username_canonical AS username_canonical2, t0.email AS email3, t0.email_canonical AS 
email_canonical4, t0.enabled AS enabled5, t0.salt AS salt6, t0.password AS password7, 
t0.last_login AS last_login8, t0.locked AS locked9, t0.expired AS expired10, t0.expires_at 
AS expires_at11, t0.confirmation_token AS confirmation_token12, t0.password_requested_at 
AS password_requested_at13, t0.roles AS roles14, t0.credentials_expired AS 
credentials_expired15, t0.credentials_expire_at AS credentials_expire_at16, t0.id AS id17, 
t0.nb_postes AS nb_postes18, t0.nb_following AS nb_following19, t0.nb_followers AS 
nb_followers20 FROM User t0 WHERE t0.username_canonical = ?' with params ["okay"]: 

SQLSTATE[42809]: Wrong object type: 7 ERROR: column notation .username applied to type 
name, which is not a composite type 
LINE 1: SELECT t0.username AS username1, t0.username_canonical AS us... 

我的查詢與MySQL工作得很好,但與PostgreSQL,我得到這個:/。 我還沒有在網上找到有關ERROR: column notation上的任何東西......如果你一個知道如何解決這個,請... :)

回答

1

你只需要轉義:

/** 
* @Entity 
* @Table("`user`") 
*/ 
class User { 
} 

那些反引號將學說在查詢中使用"user"而不是user

+0

正是......感謝提示傢伙! 但是,如果我想用戶,首字母大寫,我必須完全''\'用戶''''。 – manonthemoon

+0

當然。我只是比較喜歡PostgreSQL中的小寫字母,因爲它是慣用的。如果我的答案解決了您的問題,請不要忘記標記爲正確的答案。 –

+0

是的,我忘了標記^^。 再次感謝 – manonthemoon