ggsonic 发表于 2013-1-30 01:33:35

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
页: [1]
查看完整版本: Python Postgresql SQLAlchemy drop_all