Laravel Artisan Migrate 不创建表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28203805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:47:08  来源:igfitidea点击:

Laravel Artisan Migrate Not Creating Tables

phpmysqllaravellaravel-4artisan

提问by Alex Pelletier

I have followed the tutorial (here) to setup my app. Then I tried to replicate the steps to create more tables, so I ran a few command in the terminal like:

我已经按照教程(这里)来设置我的应用程序。然后我尝试复制创建更多表的步骤,所以我在终端中运行了一些命令,例如:

php artisan migrate:make create_generalUserInfo_table

Then in the create_generalUserInfo_table file I added:

然后在 create_generalUserInfo_table 文件中我添加了:

<?php

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

class CreateGeneralUserInfoTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('generalUserInfo', function($table){
            $table->increments('id');
            $table->integer('user_id');
            $table->string('firstname', 100);
            $table->string('lastname', 100);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

}

Then Back to terminal I ran:

然后回到终端我跑了:

php artisan migrate:refresh

It is adding the migrants but the tables are not being create in mysql. the Users table from the initial tutorial was created

它正在添加移民,但没有在 mysql 中创建表。创建了初始教程中的用户表

Migrated: 2015_01_28_055418_create_users_table
Migrated: 2015_01_28_213951_create_imprints_table
Migrated: 2015_01_28_214023_create_generalUserInfo_table
Migrated: 2015_01_28_214103_create_roles_table
Migrated: 2015_01_28_214114_create_role_user_table
Migrated: 2015_01_28_214146_create_comments_table
Migrated: 2015_01_28_214159_create_books_table

回答by baao

Try to change this line:

尝试更改此行:

Schema::create('generalUserInfo', function($table){

to

Schema::create('generalUserInfo', function(Blueprint $table){

and run the migration command like this:

并像这样运行迁移命令:

php artisan migrate

You should also make sure that

您还应该确保

  • your migration table doesn't have those tables inserted as migrated
  • your database credentials are correct and point to the correct DB
  • 您的迁移表没有将这些表作为迁移插入
  • 您的数据库凭据正确并指向正确的数据库