Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel,删除级联上的迁移参考表字符串格式_Php_Sql_Laravel - Fatal编程技术网

Php laravel,删除级联上的迁移参考表字符串格式

Php laravel,删除级联上的迁移参考表字符串格式,php,sql,laravel,Php,Sql,Laravel,如何使用字符串格式建立两个表之间的关系?我发现了错误 SQLSTATE[HY000]:一般错误:1005无法创建表 …订单定制(错误号:150“外键约束为 格式不正确”)(SQL:alter tableordercustomizesadd 约束orderscustomizes\u userorder\u id\u foreign外键 (userorder\u id)删除时引用userorders(order\u number) 级联) 主表: Schema::create('userord

如何使用字符串格式建立两个表之间的关系?我发现了错误

SQLSTATE[HY000]:一般错误:1005无法创建表
订单定制
(错误号:150“外键约束为 格式不正确”)(SQL:alter table
ordercustomizes
add 约束
orderscustomizes\u userorder\u id\u foreign
外键 (
userorder\u id
)删除时引用
userorders
order\u number
) 级联)

主表:

   Schema::create('userorders', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->integer('product_id')->unsigned();
        $table->integer('storeinfo_id')->unsigned();
        $table->integer('user_id')->unsigned();
         $table->string('order_number');          

您需要首先为
order\u number
字段(在
userorders
表中)创建索引

您可以在创建表时使用:
$table->string('order_number')->index()进行操作

或者您可以更改现有表,只需使用以下命令创建一个新索引:
$table->index('order_number')

为什么是字符串格式?因为我以字符串格式存储订单号,并且由于系统原因无法更改,那么为什么不直接引用的userorders\u id,因为它完全相同?请您帮助我执行此操作以进行字符串引用?否,在
userorders
表格创建中<代码>$table->string('order_number')->index()如果该表已存在,请更改该表。我不能完全肯定这会解决你的问题,我不能为你尝试。所以不要在生产中尝试:)
   Schema::create('userorders', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->integer('product_id')->unsigned();
        $table->integer('storeinfo_id')->unsigned();
        $table->integer('user_id')->unsigned();
         $table->string('order_number');