You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a migration-managed table is system versioned, the artisan command migrate:fresh command does not drop the table, and subsequently bringing the migrations up fails, since the migration tries to create a table that already exists.
The issue occurs because a system versioned table type is SYSTEM VERSIONED, and not BASE TABLE. When collecting the tables to be dropped, the system versioned table is not selected. Selecting SYSTEM VERSIONED tables fixes the issue.
I am willing to provide a PR fixing the problem, but it seems like it might be a risky change, I don't know. Please advise.
Steps To Reproduce
Create base laravel project: composer create-project laravel/laravel example-app
Setup MariaDB 10.7+(ish?) and configure .env to connect to the database.
Run the default migrations with php artisan migrate
Create a new migration php artisan make:migration add_users_table_versioning
Execute the add versioning statement in the migration file:
publicfunctionup(): void
{
\Illuminate\Support\Facades\DB::statement("ALTER TABLE users ADD SYSTEM VERSIONING;");
}
Run the migration. It works.
Run php artisan migrate:fresh
The command will fail with the message:
...
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
...
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Laravel Version
10.37.3
PHP Version
8.2.12
Database Driver & Version
MariaDB 10.7
Description
MariaDB supports System Versioned Tables, allowing operations on temporal data.
If a migration-managed table is system versioned, the artisan command
migrate:fresh
command does not drop the table, and subsequently bringing the migrations up fails, since the migration tries to create a table that already exists.The issue occurs because a system versioned table type is
SYSTEM VERSIONED
, and notBASE TABLE
. When collecting the tables to be dropped, the system versioned table is not selected. SelectingSYSTEM VERSIONED
tables fixes the issue.I am willing to provide a PR fixing the problem, but it seems like it might be a risky change, I don't know. Please advise.
Steps To Reproduce
composer create-project laravel/laravel example-app
.env
to connect to the database.php artisan migrate
php artisan make:migration add_users_table_versioning
php artisan migrate:fresh
The command will fail with the message:
... SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists ...
"from information_schema.tables where table_schema = %s and table_type = 'BASE TABLE' or table_type = 'SYSTEM VERSIONED' "
php artisan migrate:fresh
The command runs successfully.
The text was updated successfully, but these errors were encountered: