我有一个表“ invoice_relations”,它是变形表。 所以在迁移中,我写道:
$ table-> morphs('invoice_relations');
但是在以以下方式运行迁移时会出错,
语法错误或访问冲突:1059标识符na
我在/ var / www / html / st / sales-tantra / vendor / doctrine / dbal /
中'invoice_relations_invoice_relations_id_invoice_relations_type_index'太长
lib / Doctrine / DBAL / Driver / PDOStatement.php:105
答案 0 :(得分:1)
更改您的
$table->morphs('invoice_relations');
对此:
$table->morphs('invoice_relations', 'invoice_relations_morpf_key');
或者这个:
$table->unsignedInteger("invoice_relations_id");
$table->string("invoice_relations_type");
$table->index(["invoice_relations_id", "invoice_relations_type"], "YOUR_INDEX_NAME");
但是我认为多态关系的名称以“ able”结尾,例如“ relationable”。
https://laravel.com/docs/5.6/eloquent-relationships#polymorphic-relations