我删除了用户Laravel之后的迁移文件然后创造了一个新的。血已经干了,我干这行太久了。迁移文件中的类名是CreateUsersTable我把它改成了CreateUserTable. 我删除了数据库,从一开始…我清除了Laravel的缓存,但是…文学真的什么都没有……它在哪里缓存?1-2小时前我删除了另一个迁移文件,但Laravel并不真正关心它的信息在哪里?
错误信息:
IlluminateDatabaseQueryException
C:xampphtdocschikchika>php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (9.05ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (11.17ms)
Migrating: 2019_12_14_000001_create_personal_access_tokens_table
Migrated: 2019_12_14_000001_create_personal_access_tokens_table (24.01ms)
Migrating: 2022_06_21_083427_followers
Migrated: 2022_06_21_083427_followers (6.22ms)
Migrating: 2022_06_21_084259_email_verification
Migrated: 2022_06_21_084259_email_verification (6.40ms)
Migrating: 2022_06_21_084605_search_keywords
Migrated: 2022_06_21_084605_search_keywords (7.15ms)
Migrating: 2022_06_21_084834_dm_conversition
Migrated: 2022_06_21_084834_dm_conversition (7.65ms)
Migrating: 2022_06_21_085432_dm_messages
Migrated: 2022_06_21_085432_dm_messages (6.13ms)
Migrating: 2022_06_21_085828_posts
Migrated: 2022_06_21_085828_posts (5.89ms)
Migrating: 2022_06_21_090526_post_files
Migrated: 2022_06_21_090526_post_files (6.21ms)
Migrating: 2022_06_21_090756_post_reactions
Migrated: 2022_06_21_090756_post_reactions (6.63ms)
Migrating: 2022_06_21_091042_comments
Migrated: 2022_06_21_091042_comments (7.98ms)
Migrating: 2022_06_21_092616_comment_reactions
Migrated: 2022_06_21_092616_comment_reactions (6.44ms)
Migrating: 2022_06_21_092807_system
Migrated: 2022_06_21_092807_system (11.89ms)
PHP Fatal error: Cannot declare class CreateUsersTable, because the name is already in use in C:xampp
htdocschikchikadatabasemigrations2022_06_21_124328_users.php on line 7
SymfonyComponentErrorHandlerErrorFatalError
Cannot declare class CreateUsersTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_users.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUsersTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
11▕ *
WhoopsExceptionErrorException
Cannot declare class CreateUsersTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_users.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUsersTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
11▕ *
1 C:xampphtdocschikchikavendorfilpwhoopssrcWhoopsRun.php:486
WhoopsRun::handleError("Cannot declare class CreateUsersTable, because the name is already in use
", "C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_users.php")
2 [internal]:0
WhoopsRun::handleShutdown()
C:xampphtdocschikchika>php artisan migrate
PHP Fatal error: Cannot declare class CreateUserTable, because the name is already in use in C:xampph
tdocschikchikadatabasemigrations2022_06_21_124328_users.php on line 7
SymfonyComponentErrorHandlerErrorFatalError
Cannot declare class CreateUserTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_users.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
C:xampphtdocschikchika>php artisan migrate
PHP Fatal error: Cannot declare class CreateUserTable, because the name is already in use in C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php on line 7
SymfonyComponentErrorHandlerErrorFatalError
Cannot declare class CreateUserTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUserTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
11▕ *
WhoopsExceptionErrorException
Cannot declare class CreateUserTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUserTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
C:xampphtdocschikchika>php artisan migrate
PHP Fatal error: Cannot declare class CreateUserTable, because the name is already in use in C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php on line 7
SymfonyComponentErrorHandlerErrorFatalError
Cannot declare class CreateUserTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUserTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
11▕ *
WhoopsExceptionErrorException
Cannot declare class CreateUserTable, because the name is already in use
at C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php:7
3▕ use IlluminateDatabaseMigrationsMigration;
4▕ use IlluminateDatabaseSchemaBlueprint;
5▕ use IlluminateSupportFacadesSchema;
6▕
➜ 7▕ class CreateUserTable extends Migration
8▕ {
9▕ /**
10▕ * Run the migrations.
11▕ *
1 C:xampphtdocschikchikavendorfilpwhoopssrcWhoopsRun.php:486
WhoopsRun::handleError("Cannot declare class CreateUserTable, because the name is already in use", "C:xampphtdocschikchikadatabasemigrations2022_06_21_124328_user.php")
2 [internal]:0
WhoopsRun::handleShutdown()
C:xampphtdocschikchika>
这是我的2022_06_21_124328_user.php":
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
class CreateUserTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('username');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->timestamp('account_verified')->nullable();
$table->integer('level')->default(0); // 0 - member, 1 - moder, 2 - admin
$table->string('bio')->nullable();
$table->string('avatar')->nullable();
$table->string('cover')->nullable();
$table->integer('audience')->default(0); // 0 - public, 1 - private
$table->timestamp('birth_date')->nullable();
$table->string('location')->nullable();
$table->string('website')->nullable();
$table->integer('disabled')->default(0);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
您可以使用anonymous migration
,因为Laravel开始推荐它如下:
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flights', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('airline');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('flights');
}
};
参考:https://laravel.com/docs/9.x/migrations migration-structure
希望我的解决方案能帮到你:使您的迁移名称与类名称相同。因此,如果您的类名为CreateUserTable,那么迁移名称应该与以下内容完全相同:
CreateUserTable => create_user_table.php