gpt4 book ai didi

php - 拉维尔 5 : php artisan migrate:refresh

转载 作者:可可西里 更新时间:2023-11-01 00:56:18 26 4
gpt4 key购买 nike

我正在做一个 laravel 项目,每次我更改我的表(添加或删除列)并运行 php artisan migrate:refresh。我收到此错误:

[Symfony\Component\Debug\Exception\FatalErrorException] Can't use method return value in write context

尝试的解决方案:

  1. 运行 composer dump-autoload(失败)
  2. 在数据库中删除表,删除迁移文件并重新启动(有效)

上一个迁移文件:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('post_id');
$table->string('body');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('comments');
}
}

更改的迁移文件:

    <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('post_id');
$table->string('body');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('comments');
}
}

我在up函数的change文件中添加了user_id

最佳答案

试试这个对我有用的命令

php artisan migrate:fresh

但是,要小心!此命令将从您的数据库中删除所有数据:

Note: The migrate:fresh command will drop all tables from the database and then execute the migrate command.

as per Laravel docs 9.x .

关于php - 拉维尔 5 : php artisan migrate:refresh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com