[英]Laravel 9.x Terminal can not migrate table
Trying to migrate a users table.尝试迁移用户表。 Already have 1 table at DB.
DB 已经有 1 张桌子。 It's
Contacts
for contact form.这是
Contacts
表格的联系人。 Trying to migrate a users
table.尝试迁移
users
表。 Created my table with terminal $ php artisan make:migration create_users_table
使用终端
$ php artisan make:migration create_users_table
创建了我的表
Had the following code in it.里面有下面的代码。
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('username')->unique();
$table->timestamp('email_verified_at')();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
};
When I tried to migrate the table terminal returns an error.当我尝试迁移表终端时返回错误。
I run php artisan migrate
and it returns Migrating: create_contacts_table
我运行
php artisan migrate
并返回Migrating: create_contacts_table
"I'm trying to migrate users
table and because of the contacts table already exist it says table already exists : 1050 ...
" “我正在尝试迁移
users
表,并且由于联系人表已经存在,它说table already exists : 1050 ...
”
Tried to give an argument as it said on the website but didn't work either.试图像网站上所说的那样给出一个论点,但也没有奏效。 I tried this
$ php artisan migrate [--path[C:\xampp\htdocs\custom\database\migrations\2022_05_03_121341_create_users_table.php]]
我试过这个
$ php artisan migrate [--path[C:\xampp\htdocs\custom\database\migrations\2022_05_03_121341_create_users_table.php]]
but it returned No arguments expected for 'migrate' command但它返回 No arguments expected for 'migrate' 命令
How can I change the directory of migrate command?如何更改 migrate 命令的目录? Or how can I solve this problem.
或者我该如何解决这个问题。
so first change timestamp line and put this line:所以首先更改时间戳行并放入此行:
$table->timestamp('email_verified_at')->nullable();
then in command line use:然后在命令行中使用:
php artisan migrate:fresh
public function down()
{
Schema::table('users', function($table) {
$table->dropUnique(['email']);
$table->dropColumn('email');
$table->dropUnique(['username']);
$table->dropColumn('username');
});
Schema::dropIfExists('users');
}
run-> php artisan migrate:refresh And don't forget before running add drop uniques at down method. run-> php artisan migrate:refresh 在运行 add drop uniques at down 方法之前不要忘记。
试试这个:
php artisan migrate:refresh --path=/database/migrations/your_file_name.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.