Mysql 用原始串进行Knex偏移

Mysql 用原始串进行Knex偏移,mysql,knex.js,Mysql,Knex.js,我正在尝试使用原始sql运行knex迁移以创建一个表,而不是在knex中写出它。这里怎么了?我使用es6模板字符串跨越多行,但它没有迁移 这是我得到的错误 错误:ER_PARSE_错误:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解在“CREATE TABLEmg\u customer\u entity\u varchar”附近使用的正确语法( value\u idint(11)第22行的非空AU' 这是我的密码: require('babel-register')

我正在尝试使用原始sql运行knex迁移以创建一个表,而不是在knex中写出它。这里怎么了?我使用es6模板字符串跨越多行,但它没有迁移

这是我得到的错误

错误:ER_PARSE_错误:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解在“CREATE TABLE
mg\u customer\u entity\u varchar”附近使用的正确语法(
value\u id
int(11)第22行的非空AU'

这是我的密码:

require('babel-register')


exports.up = function(knex, Promise) {
  let raw = `
    CREATE TABLE \`mg_customer_entity\` (
      \`entity_id\` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
      \`entity_type_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
      \`attribute_set_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id',
      \`website_id\` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id',
      \`email\` varchar(255) DEFAULT NULL COMMENT 'Email',
      \`group_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Group Id',
      \`increment_id\` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
      \`store_id\` smallint(5) unsigned DEFAULT '0' COMMENT 'Store Id',
      \`created_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Created At',
      \`updated_at\` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Updated At',
      \`is_active\` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Is Active',
      \`disable_auto_group_change\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Disable automatic group change based on VAT ID',
      PRIMARY KEY (\`entity_id\`),
      UNIQUE KEY \`UNQ_MG_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID\` (\`email\`,\`website_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_STORE_ID\` (\`store_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_ENTITY_TYPE_ID\` (\`entity_type_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID\` (\`email\`,\`website_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_WEBSITE_ID\` (\`website_id\`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer Entity';

    CREATE TABLE \`mg_customer_entity_varchar\` (
      \`value_id\` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value Id',
      \`entity_type_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
      \`attribute_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Id',
      \`entity_id\` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Id',
      \`value\` varchar(255) DEFAULT NULL COMMENT 'Value',
      PRIMARY KEY (\`value_id\`),
      UNIQUE KEY \`UNQ_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID\` (\`entity_id\`,\`attribute_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_TYPE_ID\` (\`entity_type_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ATTRIBUTE_ID\` (\`attribute_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID\` (\`entity_id\`),
      KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_VALUE\` (\`entity_id\`,\`attribute_id\`,\`value\`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer Entity Varchar';
  `
  return knex.schema.raw(raw)
};

exports.down = function(knex, Promise) {
  return knex.schema
    .dropTableIfExists('mg_customer_entity')
    .dropTableIfExists('mg_customer_entity_varchar')
};
  • 我没有正确使用巴别塔寄存器
  • 必须在
  • 处将更新的时间戳从'0000-00-00 00:00:00'更改为当前时间戳 迁移/20160908144316_beerhawkAuth.js

    迁移-es6/20160908144316_beerhawkAuth.js

    require('babel-register')
    let value = require('../migrations-es6/20160908144316_beerhawkAuth.js')
    exports.up = value.up
    exports.down = value.down
    
    export let up = function(knex, Promise) {
      let create_mg_customer_entity = `
      CREATE TABLE \`mg_customer_entity\` (
        \`entity_id\` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
        \`entity_type_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
        \`attribute_set_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id',
        \`website_id\` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id',
        \`email\` varchar(255) DEFAULT NULL COMMENT 'Email',
        \`group_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Group Id',
        \`increment_id\` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
        \`store_id\` smallint(5) unsigned DEFAULT '0' COMMENT 'Store Id',
        \`created_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Created At',
        \`updated_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Updated At',
        \`is_active\` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Is Active',
        \`disable_auto_group_change\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Disable automatic group change based on VAT ID',
        PRIMARY KEY (\`entity_id\`),
        UNIQUE KEY \`UNQ_MG_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID\` (\`email\`,\`website_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_STORE_ID\` (\`store_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_ENTITY_TYPE_ID\` (\`entity_type_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID\` (\`email\`,\`website_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_WEBSITE_ID\` (\`website_id\`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer Entity';
      `
      let create_mg_customer_entity_varchar = `
      CREATE TABLE \`mg_customer_entity_varchar\` (
        \`value_id\` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value Id',
        \`entity_type_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
        \`attribute_id\` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Id',
        \`entity_id\` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Id',
        \`value\` varchar(255) DEFAULT NULL COMMENT 'Value',
        PRIMARY KEY (\`value_id\`),
        UNIQUE KEY \`UNQ_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID\` (\`entity_id\`,\`attribute_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_TYPE_ID\` (\`entity_type_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ATTRIBUTE_ID\` (\`attribute_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID\` (\`entity_id\`),
        KEY \`IDX_mg_CUSTOMER_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_VALUE\` (\`entity_id\`,\`attribute_id\`,\`value\`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer Entity Varchar';
      `
      return knex.schema
      .raw(create_mg_customer_entity)
      .raw(create_mg_customer_entity_varchar)
    };
    
    export let down = function(knex, Promise) {
      return knex.schema
        .dropTableIfExists('mg_customer_entity')
        .dropTableIfExists('mg_customer_entity_varchar')
    };