duanbing6955 2013-09-11 16:18
浏览 104
已采纳

zf2 doctrine2如何在实体列中使用tinyint数据类型

I am using Doctrine 2 ORM with ZF2.

/**
 * 
 * @ORM\Column(type="tinyint", options={"default" = 1})
 */
protected $isActive;

How can I create tinyint type of column, as I can see in support data type of doctrine, it does not exist.

Commandline># ./vendor/bin/doctrine-module orm:validate-schema

[Mapping]  FAIL - The entity-class 'Application\Entity\User' mapping is invalid:
* The field 'Application\Entity\User#isActive' uses a non-existant type 'tinyint'.

  [Doctrine\DBAL\DBALException]
  Unknown column type "tinyint" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypeMap(). If this
  error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseT
  ypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.


orm:validate-schema
  • 写回答

4条回答 默认 最新

  • dongtong848825 2013-09-11 16:27
    关注

    Use columnDefinition, though it is not an ideal solution but serve the purpose.

    /**
     * 
     * @ORM\Column(columnDefinition="TINYINT DEFAULT 1 NOT NULL")
     */
    protected $isActive;
    

    columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. However you should make careful use of this feature and the consequences. SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”.

    Additionally you should remember that the “type” attribute still handles the conversion between PHP and Database values. If you use this attribute on a column that is used for joins between tables you should also take a look at @JoinColumn.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失