-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
sqlite "rename table" is wrong #1065
Labels
Comments
this is not related to constraints or batch, this is the RENAME TABLE command op, can you confirm this patch resolves thanks diff --git a/alembic/ddl/sqlite.py b/alembic/ddl/sqlite.py
index 9b38766..f986c32 100644
--- a/alembic/ddl/sqlite.py
+++ b/alembic/ddl/sqlite.py
@@ -11,12 +11,17 @@ from sqlalchemy import cast
from sqlalchemy import JSON
from sqlalchemy import schema
from sqlalchemy import sql
+from sqlalchemy.ext.compiler import compiles
+from .base import alter_table
+from .base import format_table_name
+from .base import RenameTable
from .impl import DefaultImpl
from .. import util
if TYPE_CHECKING:
from sqlalchemy.engine.reflection import Inspector
+ from sqlalchemy.sql.compiler import DDLCompiler
from sqlalchemy.sql.elements import Cast
from sqlalchemy.sql.elements import ClauseElement
from sqlalchemy.sql.schema import Column
@@ -178,6 +183,16 @@ class SQLiteImpl(DefaultImpl):
)
+@compiles(RenameTable, "sqlite")
+def visit_rename_table(
+ element: "RenameTable", compiler: "DDLCompiler", **kw
+) -> str:
+ return "%s RENAME TO %s" % (
+ alter_table(compiler, element.table_name, element.schema),
+ format_table_name(compiler, element.new_table_name, None),
+ )
+
+
# @compiles(AddColumn, 'sqlite')
# def visit_add_column(element, compiler, **kw):
# return "%s %s" % ( |
Yep, that works as expected:
|
Mike Bayer has proposed a fix for this issue in the main branch: implement SQLite RENAME TABLE w schema syntax https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/3985 |
thanks for confirming |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
During the batch operation to drop a non-null constraints, the final step is to rename the temporary table to the real table name. However, when the table is in a schema, alembic generates DDL of the form
ALTER TABLE scehma._alembic_tmp_table RENAME TO schema.table
. However, the sqlite ALTER TABLE syntax does not expect or allow a schema name on the target table name.Expected behavior
The
ALTER TABLE
statement should respect the sqlite grammar and be of the formALTER TABLE scehma._alembic_tmp_table RENAME TO table
To Reproduce
Error
Versions.
Have a nice day!
Thanks!
The text was updated successfully, but these errors were encountered: