use*_*351 5 php drupal drupal-7
我正在编写一个新的Drupal 7模块(Drupal 7.10,安装了Date 7.x-2.0-rc1,安装了Schema 7.x-1.0-beta3)我在mymodule.install中定义了一个表:
$schema['museums_tickets']= array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'day' => array(
'type' => 'datetime',
'mysql_type' => 'DATETIME',
'not null' => TRUE,
),
'tickets' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'ticket_code' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('nid', 'day','ticket_code'),
);
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误:
Field museums_tickets.day: no Schema type for mysql type datetime.
museums_tickets.day: no type for Schema type datetime.
Field museums_tickets.day: no Schema type for type datetime.
Run Code Online (Sandbox Code Playgroud)
如果我使用,同样适用
'type' => 'datetime:normal',
Run Code Online (Sandbox Code Playgroud)
我想知道如何解决这个问题.我不想将日期存储为时间戳,因为另一个人写了很多代码,显然我不想重写所有代码.我已经看过drupal 7自定义架构错误日期时间,但答案不起作用.也许我做错了什么,但我找不到什么.
先感谢您.
kub*_*bio 16
如果你查看Date模块的模式,你会发现类似的东西
'day' => array(
'type' => 'datetime',
'mysql_type' => 'datetime',
)
Run Code Online (Sandbox Code Playgroud)
实际上Clive的答案是我首先选择的那个,但后来给了我Views模块的问题.
Date模块的这种实现节省了我的一天
以下适用于我(Drupal 7.10):
'day' => array(
'mysql_type' => 'DATETIME',
'not null' => TRUE,
)
Run Code Online (Sandbox Code Playgroud)
(注意mysql_type钥匙而不是 type)
来自Schema文档:
如果需要使用上述类型的官方支持列表中未包含的记录类型,则可以为每个数据库后端指定类型.在这种情况下,您可以省略type参数
datetime在Drupal 7中不是允许的泛型类型,因此将type密钥留在那里总是会导致错误.