Laravel 迁移 - 表未创建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18929213/
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 08:27:27  来源:igfitidea点击:

Laravel Migration - table not getting created

mysqllaravellaravel-4

提问by StackOverflowNewbie

I'm trying to learn Laravel. I'm following the Quickstart documentation but have gotten into a problem with Migrations. I'm at this step: http://laravel.com/docs/quick#creating-a-migration

我正在努力学习 Laravel。我正在关注快速入门文档,但遇到了迁移问题。我在这一步:http: //laravel.com/docs/quick#creating-a-migration

When I run the command php artisan migrate, the command line displays the following:

当我运行命令时php artisan migrate,命令行显示以下内容:

c:\wamp\www\laravel>php artisan migrate
Migration table created successfully.
Migrated: 2013_09_21_040037_create_users_table

In the database, I see a migrationstable created with 1 record. However, I do not see a userstable. So, I can't continue on to the ORM portion of the tutorial.

在数据库中,我看到一个migrations用 1 条记录创建的表。但是,我没有看到一张users桌子。因此,我无法继续学习本教程的 ORM 部分。

Any ideas what I might be doing wrong? Why isn't the userstable getting created?

任何想法我可能做错了什么?为什么没有users创建表?

EDIT 1 (original migration file):

编辑 1(原始迁移文件):

<?php

use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
            Schema::create('users', function($table)
            {
                $table->increments('id');
                $table->string('email')->unique();
                $table->string('name');
                $table->timestamps();
            });
    }

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

}

回答by devo

The updated Laravel should use Blueprintfor database schema creation. So try to change your user migration file content like this,

更新后的 Laravel 应该Blueprint用于创建数据库模式。所以试着像这样改变你的用户迁移文件内容,

<?php

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

class CreateUsersTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function(Blueprint $table) {
            $table->integer('id', true);
            $table->string('name');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

}

Then run,

然后跑,

  php artisan migrate:rollback 

and then migrate again.

然后再次迁移。

Read the APIdocumentation here http://laravel.com/api/class-Illuminate.Database.Schema.Blueprint.html

API此处阅读文档http://laravel.com/api/class-Illuminate.Database.Schema.Blueprint.html