微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – drupal 7自定义架构错误datetime

我有以下架构(从自定义模块中的schema module(7.x-1.0-beta3)现有表生成.

function myproject_entities_schema() {

// ---------------------------------------------------------------------------------
// MESSAGE
// ---------------------------------------------------------------------------------
$schema['myproject_entity_message'] = array(
    'description' => 'The base table for myproject message instances',
    'fields' => array(
        'id' => array(
            'description' => 'The primary identifier for a message instance',
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'weekendday' => array(
            'description' => 'Whether this message gets send on a weekendday(1) or on a workday(0)',
            'type' => 'int',
            'size' => 'tiny',
            'not null' => TRUE,
            'default' => 0,
        ),
        'day' => array(
            'description' => 'Numbered day of campaign schedule',
            'type' => 'int',
            'not null' => TRUE,
        ),
        'content' => array(
            'description' => 'Message content',
            'type' => 'text',
            'not null' => TRUE,
        ),
        'time_to_send' => array(
            'description' => 'When the message should arrive at the user',
            'type' => 'datetime',
            'not null' => TRUE,
        ),
        'campaign_fk' => array(
            'description' => 'the foreign key of the campaign this message belongs to',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => FALSE,
        ),
        'user_id' => array(
            'description' => 'The user id this message is generated for',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'pool_id' => array(
            'description' => 'The pool node id this message was generated from',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'message_template_id' => array(
            'description' => 'The node id of the message template this message was generated from',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
        'CAMPAIGN' => array('campaign_fk'),
        'MESSAGE_TEMPLATE' => array('message_template_id'),
        'POOL' => array('pool_id'),
        'USER' => array('user_id'),
    ),
);

// ---------------------------------------------------------------------------------
// CAMPAIGN
// ---------------------------------------------------------------------------------
$schema['myproject_entity_campaign'] = array(
    'description' => 'The base table for myproject campaigns instances',
    'fields' => array(
        'id' => array(
            'description' => 'The primary identifier for a campaign instance',
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'schedule' => array(
            'description' => 'The schedule of the campaign in text format.',
            'type' => 'text',
            'not null' => TRUE,
        ),
        'interruptible' => array(
            'description' => 'Whether this campaign is interruptible or not',
            'type' => 'int',
            'size' => 'tiny',
            'not null' => TRUE,
        ),
        'campaign_template_id' => array(
            'description' => 'Node id of campaign template this instance was created from',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'product_fk' => array(
            'description' => 'Primary key of product instance this campaign belongs to',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => FALSE,
        ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
        'CAMPAIGN_TEMPLATE' => array('campaign_template_id'),
        'PRODUCT' => array('product_fk'),
    ),
);

// ---------------------------------------------------------------------------------
// PRODUCT
// ---------------------------------------------------------------------------------
$schema['myproject_entity_product'] = array(
    'description' => 'The base table for myproject product instances',
    'fields' => array(
        'id' => array(
            'description' => 'The primary identifier for a product instance',
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'start' => array(
            'description' => 'Time when the campaign started',
            'type' => 'datetime',
            'not null' => TRUE,
        ),
        'current_campaign_fk' => array(
            'description' => 'Foreign key of currently running campaign instance',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => FALSE,
        ),
        'next_campaign_fk' => array(
            'description' => 'Foreign key of campaign instance to run next',
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => FALSE,
        ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
        'CURRENT' => array('current_campaign_fk'),
        'NEXT' => array('next_campaign_fk'),
    ),
);

return $schema;
}

当我尝试安装模块并因此创建模式时,我总是得到以下通知(我不认为是失败的主要原因):

Notice: Undefined index: datetime:normal in DatabaseSchema_MysqL->processField() (line 200 of /Users/xxx/Repos/myproject/includes/database/MysqL/schema.inc).

并出现以下错误

PDOException: sqlSTATE[42000]: Syntax error or access violation: 1064 You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'NOT NULL COMMENT 'When the message should arrive at the user', `campaign_fk` IN' at line 6: CREATE TABLE {myproject_entity_message} ( `id` INT unsigned NOT NULL auto_increment COMMENT 'The primary identifier for a message instance', `weekendday` tinyint NOT NULL DEFAULT 0 COMMENT 'Whether this message gets send on a weekendday(1) or on a workday(0)', `day` INT NOT NULL COMMENT 'Numbered day of campaign schedule', `content` TEXT NOT NULL COMMENT 'Message content', `time_to_send` NOT NULL COMMENT 'When the message should arrive at the user', `campaign_fk` INT unsigned NULL DEFAULT NULL COMMENT 'the foreign key of the campaign this message belongs to', `user_id` INT unsigned NOT NULL COMMENT 'The user id this message is generated for', `pool_id` INT unsigned NOT NULL COMMENT 'The pool node id this message was generated from', `message_template_id` INT unsigned NOT NULL COMMENT 'The node id of the message template this message was generated from', PRIMARY KEY (`id`), INDEX `CAMPAIGN` (`campaign_fk`), INDEX `MESSAGE_TEMPLATE` (`message_template_id`), INDEX `POOL` (`pool_id`), INDEX `USER` (`user_id`) ) ENGINE = InnoDB DEFAULT CHaraCTER SET utf8 COLLATE utf8_general_ci COMMENT 'The base table for myproject message instances'; Array ( ) in db_create_table() (line 2684 of /Users/xxx/Repos/myproject/includes/database/database.inc).

我在架构定义中搜索错误但找不到任何错误.另外,我没有看到sql语句究竟出了什么问题.

我的服务器设置是:
Apache / 2.2.20(Unix)mod_ssl / 2.2.20 OpenSSL / 0.9.8r DAV / 2 PHP / 5.3.6与Suhosin-Patch
MysqL客户端版本:MysqLnd 5.0.8-dev – 20102224 – $Revision:308673 $

有人看到这里有什么不对吗?

解决方法:

我认为您需要使用datetime:normal作为日期时间列类型的键.

'time_to_send' => array(
  'description' => 'When the message should arrive at the user',
  'type' => 'datetime:normal',
  'not null' => TRUE,
),

除此之外,您可以尝试明确地将列类型指定为MysqL DATETIME:

'time_to_send' => array(
  'description' => 'When the message should arrive at the user',
  'MysqL_type' => 'DATETIME',
  'not null' => TRUE,
),

问题似乎源于是否在Drupal 7中实际允许DATETIME;看到this discussion的详细信息比我在这里可以容纳的更多:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐