Laravel 默认用户表

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

Laravel default user table

phplaravel

提问by Earthx9

I use Laravel 5.2 and want to change default user table's columns. I wrote in the CreateUsersTable

我使用 Laravel 5.2 并想更改默认用户表的列。我写在 CreateUsersTable

   public function up()
   {
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });

    Schema::table('users', function ($table) {
        $table->string('role');
        $table->string('info');
        $table->string('age');
        $table->string('hobies');
        $table->string('job');
    });
    }

and i run these commands in the git bash but user table didn't change.

我在 git bash 中运行这些命令,但用户表没有改变。

    php artisan migrate:refresh
    php artisan migrate

How can i solve it?

我该如何解决?

回答by Alexey Mezenin

You should run composer dumpauto -oafter running php artisan migratecommand to register new migrations, so they could be rolled back.

您应该composer dumpauto -o在运行php artisan migrate命令后运行以注册新迁移,以便它们可以回滚。

Try it. If it will not work, try to delete all tables, including migrationsand run this command:

尝试一下。如果它不起作用,请尝试删除所有表,包括migrations并运行以下命令:

php artisan migrate:install

回答by Rudyar Cortés

You only need to change what it inside of Schema::createand delete your Schema::table

你只需要改变它里面的内容Schema::create并删除你的Schema::table

Then, you need to implement tour down()mehod and add Schema::drop('users');in order to drop your table when you run migrate:refresh.

然后,您需要实现游览方法down()并添加Schema::drop('users');以便在运行时删除您的表migrate:refresh

You can read the 'Database migrations' in the laravel documentation for further details.

您可以阅读 laravel 文档中的“数据库迁移”以获取更多详细信息。

回答by Anri

create new migration file and do something like this

创建新的迁移文件并执行类似的操作

public function up() {
    DB::statement('ALTER TABLE user ADD some_field INT');// your query here
}

php artisan migrate

回答by alaa elgndy

delete the first statement and leave last one only . then run php artisan migrate:refresh

删除第一条语句,只保留最后一条。然后运行 ​​php artisan migrate:refresh