Python Postgresql SQLAlchemy drop_all

Python + Postgresql + SQLAlchemy fix: drop_all() fails due to circular references

Posted by dandriff on Friday September 12, 2008@01:31PM

Here is the fix, as described by this helpful guy:

from sqlalchemy.databases import postgres

class PGCascadeSchemaDropper(postgres.PGSchemaDropper):
     def visit_table(self, table):
        for column in table.columns:
            if column.default is not None:
                self.traverse_single(column.default)
        self.append("\nDROP TABLE " +
                    self.preparer.format_table(table) +
                    " CASCADE")
        self.execute()

postgres.dialect.schemadropper = PGCascadeSchemaDropper

你可能感兴趣的:(python,PostgreSQL)