Answer the question
In order to leave comments, you need to log in
Why does it give an error when creating a model with migration?
When creating a model and migration, it gave an error:
Model created successfully.
InvalidArgumentException
A CreateUsersTable class already exists.
at vendor/laravel/framework/src/Illuminate/Database/Migrations/MigrationCreator.php:102
98▕ }
99▕ }
100▕
101▕ if (class_exists($className = $this->getClassName($name))) {
➜ 102▕ throw new InvalidArgumentException("A {$className} class already exists.");
103▕ }
104▕ }
105▕
106▕ /**
+28 vendor frames
29 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '8889'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Answer the question
In order to leave comments, you need to log in
Update Laravel to version 8.74 and switch to anonymous migration classes.
To do this, create a directory /stubs
Inside create three files
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
Schema::create('{{ table }}', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('{{ table }}');
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
}
public function down()
{
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
Schema::table('{{ table }}', function (Blueprint $table) {
});
}
public function down()
{
Schema::table('{{ table }}', function (Blueprint $table) {
});
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question