question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add mssql_drop_XYZ flags to autogenerate op.drop_column() based on observation of mssql + known type-specific check constraints, defaults, FKs

See original GitHub issue

Migrated issue, originally created by Marek Baczyński (@imbaczek)

DB: SQL Server 2008R2

SQLAlchemy==0.9.3

alembic==0.6.4dev (today’s master and 0.6.3 too)

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('table', sa.Column('col1', sa.Enum('one', 'two', name='ck_col1'), nullable=True))
    op.add_column('table', sa.Column('col2', sa.Boolean(name='ck_col2'), nullable=True))
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('table', 'col2')
    op.drop_column('table', 'col1')
    ### end Alembic commands ###
$ alembic downgrade 328
INFO  [alembic.migration] Context impl MSSQLImpl.
INFO  [alembic.migration] Will assume transactional DDL.
INFO  [alembic.migration] Running downgrade 26f5521a70be -> 328b04eddf97, added table table
[...]
  File "pymssql.pyx", line 435, in pymssql.Cursor.execute (pymssql.c:6347)
sqlalchemy.exc.OperationalError: (OperationalError) (5074, "The object 'ck_col2' is dependent on column 'col2'.DB-Lib error message 5074, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 4922, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n") 'ALTER TABLE [table] DROP COLUMN col2' {}

(constraint names above are tweaked to increase readability, related to #183)


Attachments: 184.patch

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sqlalchemy-botcommented, Nov 27, 2018

Michael Bayer (@zzzeek) wrote:

note this refers to all three of: mssql_drop_default, mssql_drop_check, mssql_drop_foreign_key

0reactions
zzzeekcommented, Sep 17, 2019

the related issue is #186 which was fixed.

While it would be nice for this flag to automatically render, this is a fairly special case for now and other than having it render unconditionally in all cases, which would be wasteful, I don’t have a solution right now for how this flag could always come out correctly. If we look into doing a generalized ENUM solution, that would be separate from this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete Check Constraints - SQL Server
Deleting check constraints removes the limitations on data values that are accepted in the column or columns included in the constraint ...
Read more >
How to drop column with constraint? - sql server
First you should drop the problematic DEFAULT constraint , after that you can drop the column alter table tbloffers drop constraint ...
Read more >
SQL Injection Cheat Sheet
The SQL Injection Cheat Sheet is the definitive resource for all the technical details about the different variants of the well-known SQLi vulnerability....
Read more >
Operation Reference — Alembic 1.9.0 documentation
This so that migration instructions can be given in terms of just the string names and/or flags involved. The exceptions to this rule...
Read more >
SQL Examples
Structured data in the relational model means data that can be represented in tables -- rows and columns. Each row in a table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found