0

我正在运行全新安装的 Laravel,其中包含干净的数据库和文件。

我创建了一个名为“frooth”的表,其中包含 id、title 和 created_at 列(id PK、varchar 和 datetime)

当我运行“php artisan make:migration frooth”命令时,创建的迁移文件是空的,只包含 up() 和 down() 函数,仅此而已(没有列)

我该如何解决这个问题,我遵循官方网站中记录的框架的基本配置,我可以按预期访问和创建工匠中的功能,只有迁移它不起作用。

我使用以下命令生成了项目:composer create-project --prefer-dist laravel/laravel blog

create table laravel.frooth
(
    id         int auto_increment
        primary key,
    title      varchar(250) null,
    created_at datetime     null
);

在 database/migrations/2019_10_25_012925_frooth.php 中生成的 PHP 类:

<?php

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

class Frooth extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

控制台输出:

php artisan make:migration frooth
Created Migration: 2019_10_25_012925_frooth
4

1 回答 1

0

删除您手动创建的表并删除该迁移文件。

php artisan make:migration create_frooths_table

然后将您的列添加到新的迁移文件中。

与此类似的东西:

<?php

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

class Frooth extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('frooths', function (Blueprint $table) {

        $table->increments('id');
        $table->string('title')->nullable();
        $table->timestamps();
          }); 
        }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('frooths');
    }
}

然后运行php artisan migrate

如果使用 Laravel 6 ,id您可能需要使用$table->bigIncrements('id');

于 2019-10-25T02:29:19.847 回答