JaguarJack/migration-generator

Undefined index: lengths

Closed this issue · 7 comments

复合主键的时候导入失败

请提供具体代码。和出现 bug 的场景代码

composer之后运行php think migration:generate。tp6.0.3报错think\exception\ErrorException {#887
#severity: 8
#data: []
#message: "Undefined index: lengths"
#code: 0
#file: "D:\www\tp6\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\Index.php"
#line: 335
trace: {
D:\www\tp6\vendor\doctrine\dbal\lib\Doctrine\DBAL\Schema\Index.php:335 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\Indexes\ThinkphpMigrationIndexs.php:94 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\Indexes\ThinkphpMigrationIndexs.php:79 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\ThinkPHPMigration.php:75 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\AbstractMigration.php:131 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\ThinkPHPMigration.php:35 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Migration\AbstractMigration.php:143 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\MigrateGenerator.php:60 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Command\ThinkPHPCommand.php:57 { …}
D:\www\tp6\vendor\jaguarjack\migration-generator\src\Command\ThinkPHPCommand.php:37 { …}
D:\www\tp6\vendor\topthink\framework\src\think\console\Command.php:210 { …}
D:\www\tp6\vendor\topthink\framework\src\think\Console.php:600 { …}
D:\www\tp6\vendor\topthink\framework\src\think\Console.php:259 { …}
D:\www\tp6\vendor\topthink\framework\src\think\Console.php:196 { …}
D:\www\tp6\think:10 {
› // 应用初始化\r
› (new App())->console->run();

}
}

导了几个,碰到了一个复合主键的表就挂了,把那个复合主键表修改成普通主键就能够跑了

贴一下 SQL 出来

贴一下 SQL 出来

DROP TABLE IF EXISTS auth_assignment;
CREATE TABLE auth_assignment (
item_name varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
user_id varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
created_at int(11) NULL DEFAULT NULL,
PRIMARY KEY (item_name, user_id) USING BTREE,
CONSTRAINT auth_assignment_ibfk_1 FOREIGN KEY (item_name) REFERENCES auth_item (name) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '角色与用户对应关系表' ROW_FORMAT = Dynamic;

读取了这个表
Doctrine\DBAL\Schema\Table {#245
#_columns: array:3 [
"item_name" => Doctrine\DBAL\Schema\Column {#235
#_type: Doctrine\DBAL\Types\StringType {#112}
#_length: 64
#_precision: 10
#_scale: 0
#_unsigned: false
#_fixed: false
#_notnull: true
#_default: null
#_autoincrement: false
#_platformOptions: array:2 [
"charset" => "utf8"
"collation" => "utf8_unicode_ci"
]
#_columnDefinition: null
#_comment: null
#_customSchemaOptions: []
#_name: "item_name"
#_namespace: null
#_quoted: false
}
"user_id" => Doctrine\DBAL\Schema\Column {#236
#_type: Doctrine\DBAL\Types\StringType {#112}
#_length: 64
#_precision: 10
#_scale: 0
#_unsigned: false
#_fixed: false
#_notnull: true
#_default: null
#_autoincrement: false
#_platformOptions: array:2 [
"charset" => "utf8"
"collation" => "utf8_unicode_ci"
]
#_columnDefinition: null
#_comment: null
#_customSchemaOptions: []
#_name: "user_id"
#_namespace: null
#_quoted: false
}
"created_at" => Doctrine\DBAL\Schema\Column {#237
#_type: Doctrine\DBAL\Types\IntegerType {#106}
#_length: null
#_precision: 10
#_scale: 0
#_unsigned: true
#_fixed: false
#_notnull: false
#_default: null
#_autoincrement: false
#_platformOptions: []
#_columnDefinition: null
#_comment: null
#_customSchemaOptions: []
#_name: "created_at"
#_namespace: null
#_quoted: false
}
]
-implicitIndexes: array:1 [
"idx_2ec0490e96133afd" => Doctrine\DBAL\Schema\Index {#246
#_columns: array:1 [
"item_name" => Doctrine\DBAL\Schema\Identifier {#247
#_name: "item_name"
#_namespace: null
#_quoted: false
}
]
#_isUnique: false
#_isPrimary: false
#_flags: []
-options: []
#_name: "IDX_2EC0490E96133AFD"
#_namespace: null
#_quoted: false
}
]
#_indexes: array:2 [
"primary" => Doctrine\DBAL\Schema\Index {#242
#_columns: array:2 [
"item_name" => Doctrine\DBAL\Schema\Identifier {#243
#_name: "item_name"
#_namespace: null
#_quoted: false
}
"user_id" => Doctrine\DBAL\Schema\Identifier {#244
#_name: "user_id"
#_namespace: null
#_quoted: false
}
]
#_isUnique: true
#_isPrimary: true
#_flags: []
-options: array:1 [
"lengths" => array:2 [
0 => null
1 => null
]
]
#_name: "PRIMARY"
#_namespace: null
#_quoted: false
}
"idx_2ec0490e96133afd" => Doctrine\DBAL\Schema\Index {#246}
]
#_primaryKeyName: "primary"
#_fkConstraints: array:1 [
"auth_assignment_ibfk_1" => Doctrine\DBAL\Schema\ForeignKeyConstraint {#238
#_localTable: Doctrine\DBAL\Schema\Table {#245}
#_localColumnNames: array:1 [
"item_name" => Doctrine\DBAL\Schema\Identifier {#239
#_name: "item_name"
#_namespace: null
#_quoted: false
}
]
#_foreignTableName: Doctrine\DBAL\Schema\Identifier {#240
#_name: "auth_item"
#_namespace: null
#_quoted: false
}
#_foreignColumnNames: array:1 [
"name" => Doctrine\DBAL\Schema\Identifier {#241
#_name: "name"
#_namespace: null
#_quoted: false
}
]
#_options: array:2 [
"onDelete" => "CASCADE"
"onUpdate" => "CASCADE"
]
#_name: "auth_assignment_ibfk_1"
#_namespace: null
#_quoted: false
}
]
#_options: array:6 [
"create_options" => []
"engine" => "InnoDB"
"collation" => "utf8_unicode_ci"
"comment" => "角色与用户对应关系表"
"name" => "auth_assignment"
"origin" => array:3 [
0 => array:9 [
"Field" => "item_name"
"Type" => "varchar(64)"
"Null" => "NO"
"Key" => "PRI"
"Default" => null
"Extra" => ""
"Comment" => ""
"CharacterSet" => "utf8"
"Collation" => "utf8_unicode_ci"
]
1 => array:9 [
"Field" => "user_id"
"Type" => "varchar(64)"
"Null" => "NO"
"Key" => "PRI"
"Default" => null
"Extra" => ""
"Comment" => ""
"CharacterSet" => "utf8"
"Collation" => "utf8_unicode_ci"
]
2 => array:9 [
"Field" => "created_at"
"Type" => "int(11) unsigned"
"Null" => "YES"
"Key" => ""
"Default" => null
"Extra" => ""
"Comment" => ""
"CharacterSet" => null
"Collation" => null
]
]
]
#_schemaConfig: null
#_name: "auth_assignment"
#_namespace: null
#quoted: false
}
在 D:\www\tp6\vendor\jaguarjack\migration-generator\src\Command\ThinkPHPCommand.php 第57
file_put_contents($migrationsPath . ($key + 1) . date('YmdHis') . '
' . $table->getName() . '.php', $migrateGenerator->getMigrationContent($table));里面执行getMigrationContent报错了。

问题不在这。我测试本地组合键是可以的。可能是外键,你把外键相关联的表一并发过来。

CREATE TABLE auth_assignment (
item_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
user_id varchar(64) COLLATE utf8_unicode_ci NOT NULL,
created_at int(11) DEFAULT NULL,
PRIMARY KEY (item_name,user_id) USING BTREE,
CONSTRAINT auth_assignment_ibfk_1 FOREIGN KEY (item_name) REFERENCES auth_item (name) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='角色与用户对应关系表';

CREATE TABLE auth_item (
name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
type int(11) NOT NULL,
description text COLLATE utf8_unicode_ci,
rule_name varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
data text COLLATE utf8_unicode_ci,
created_at int(11) DEFAULT NULL,
updated_at int(11) DEFAULT NULL,
PRIMARY KEY (name) USING BTREE,
KEY rule_name (rule_name) USING BTREE,
KEY idx-auth_item-type (type) USING BTREE,
CONSTRAINT auth_item_ibfk_1 FOREIGN KEY (rule_name) REFERENCES auth_rule (name) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='角色|权限表,type=1角色,type=2权限';

CREATE TABLE auth_rule (
name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
data text COLLATE utf8_unicode_ci,
created_at int(11) DEFAULT NULL,
updated_at int(11) DEFAULT NULL,
PRIMARY KEY (name) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='规则,规则类名';

CREATE TABLE auth_item_child (
parent varchar(64) COLLATE utf8_unicode_ci NOT NULL,
child varchar(64) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (parent,child) USING BTREE,
KEY child (child) USING BTREE,
CONSTRAINT auth_item_child_ibfk_1 FOREIGN KEY (parent) REFERENCES auth_item (name) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT auth_item_child_ibfk_2 FOREIGN KEY (child) REFERENCES auth_item (name) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='角色对应的权限,parent角色,child权限名';

CREATE TABLE yii2_admin_menu (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(128) NOT NULL,
parent int(11) DEFAULT NULL,
route varchar(255) DEFAULT NULL,
order int(11) DEFAULT NULL,
data blob,
PRIMARY KEY (id) USING BTREE,
KEY parent (parent) USING BTREE,
CONSTRAINT yii2_admin_menu_ibfk_1 FOREIGN KEY (parent) REFERENCES yii2_admin_menu (id) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='管理员菜单表';
就这五个表

已添加