mysql - Laravel 迁移 - 未创建表

标签 mysql laravel laravel-4

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

当我运行命令 php artisan migrate 时,命令行显示如下:

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

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

知道我可能做错了什么吗?为什么没有创建 users 表?

编辑 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');
    }

}

最佳答案

更新后的 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');
    }

}

然后运行,

  php artisan migrate:rollback 

然后再次迁移。

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

关于mysql - Laravel 迁移 - 未创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18929213/

相关文章:

php - Laravel 使用多少成本/回合进行哈希处理?

mysql - MySQL查询有什么问题?

mysql - 查询以排除 ID 在另一个表中列出的行

php - 在 Laravel 5.1 中附加用户 ID 以干净的方式保存/更新/创建

php - Laravel错误: Trying to get property of non-object

javascript - Laravel 4 + Angular 路由无限循环

php - 如果登录,Laravel 在访问登录页面时重定向到用户仪表板

php - MySQL 中带有通配符或正则表达式的数值

mysql - 与 NVARCHAR 相比,将列设为 VARCHAR (somenumber) 有何优点?

javascript - Laravel:在允许 HTML 标签时,针对 XSS 清理用户输入