Laravel 5 未能创建新的迁移

Laravel 5 未能创建新的迁移,laravel-5,Laravel 5,我想创建一个新表,users\u profile 这是迁移代码 <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersProfileTable extends Migration { /** * Run the migrati

我想创建一个新表,users\u profile 这是迁移代码

<?php

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

class CreateUsersProfileTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users_profile', function (Blueprint $table) {
            $table->increments('id');
            $table->string('city');
            $table->string('country');
             $table->integer('users_id')->unsigned();
                $table->foreign('users_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade');               
            $table->timestamps();
        });
    }

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

只是一个建议,使用Laravel术语来避免此类问题。始终将表名定义为复数snakecase,并使用单数camelcase模型访问它们

在您的情况下,将表名更改为:
user\u profiles
,并使用
UserProfile
model自动访问它

因此,您需要在迁移中相应地更改类名:CreateUserProfilesTable

我相信这会解决你的问题

我相信您正在使用:
php artisan migrate
,由于users表已经存在,再次运行migration for users表会导致该错误

使用:
composer dump autoload
,然后
php artisan migrate:refresh

要回滚所有迁移并重新安装迁移。

只需转到数据库并删除架构表(“用户”),同时删除架构表中的条目(“迁移”),然后再次运行迁移……您的问题已经解决了……

请使用Laravel术语避免此类问题。始终将表名定义为复数snakecase,并使用单数camelcase模型访问它们。如果您的问题已得到解决,请告诉我。创建此新迁移后,您是否尝试
php artisan migrate
?如果是,则使用:
php artisan migrate:refresh
Instead我使用过php artisan migrate:refresh,即使是相同的问题,
php artisan配置:clear
then
composer dump autoload
then
php artisan migrate:refresh
<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void

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

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