Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running migrate/fresh on Microsoft SQL does not drop views #20256

Open
ambrozt opened this issue Sep 19, 2024 · 0 comments
Open

Running migrate/fresh on Microsoft SQL does not drop views #20256

ambrozt opened this issue Sep 19, 2024 · 0 comments
Labels
Milestone

Comments

@ambrozt
Copy link

ambrozt commented Sep 19, 2024

What steps will reproduce the problem?

Connect a yii2 instance with a Microsoft SQL server (tested with mcr.microsoft.com/mssql/server:2022-latest docker image and msodbcsql18 unixOdbc drivers from Microsoft installed on the PHP instance). Create a view in a Microsoft SQL database with CREATE VIEW test AS SELECT 1 AS placeholder WHERE 1 = 0; within a migration. Run yii migrate/fresh.

What is the expected result?

All the tables and views in the database should be dropped and then recreated.

What do you get instead?

An error when the create view migration is executed after the database refresh.

Exception: SQLSTATE[42S01]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]There is already an object named 'test' in the database.

Additional info

The yii\console\controllers\MigrateController function isViewRelated only identifies drop view errors for SQLite and MySQL, which then causes the views to be ignored when the truncateDatabase function is executed. A Microsoft SQL specific condition should be added to the existing array to identify an error when using DROP TABLE on a view.

Q A
Yii version 2.0.51
PHP version 8.3.8
Operating system CentOS Stream 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants