【问题标题】:Symfony 2 - PostgreSQL - SQLSTATE[42809]: Wrong object type: 7 ERROR: column notationSymfony 2 - PostgreSQL - SQLSTATE [42809]:错误的对象类型:7 错误:列符号
【发布时间】:2014-02-08 04:49:48
【问题描述】:

我目前正在学习 symfony 2。 之前,我使用的是 MySQL,但我想尝试一下 Symfony 2 和学说的强大功能。所以我想从 MySQL 切换到 PostgreSQL。 我已经安装好一切......数据库是使用教义命令创建的,转储也成功......当我想从主页注册一个新用户时。我有这个例外:

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 的信息……如果你们中的任何一个知道如何解决这个问题,请……:)

【问题讨论】:

    标签: php postgresql symfony doctrine-orm debian


    【解决方案1】:

    你只需要转义:

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

    这些反引号将使 Doctrine 在查询中使用 "user" 而不是 user

    【讨论】:

    • 完全正确...感谢您的提示!但是如果我想要用户,第一个字母为大写,我必须完全做到"`User`"
    • 当然。我只喜欢 PostgreSQL 中小写的所有内容,因为它是惯用的。如果我的回答解决了您的问题,请不要忘记将其标记为正确的。
    猜你喜欢
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    相关资源
    最近更新 更多