How to delete a table in SQLAlchemy?

Just call drop() against the table object. From the docs: Issue a DROP statement for this Table, using the given Connectable for connectivity. In your case it should be: User.__table__.drop() If you get an exception like: sqlalchemy.exc.UnboundExecutionError: Table object ‘my_users’ is not bound to an Engine or Connection. Execution can not proceed without a database … Read more

DROP IF EXISTS VS DROP?

Standard SQL syntax is DROP TABLE table_name; IF EXISTS is not standard; different platforms might support it with different syntax, or not support it at all. In PostgreSQL, the syntax is DROP TABLE IF EXISTS table_name; The first one will throw an error if the table doesn’t exist, or if other database objects depend on … Read more

SQL DROP TABLE foreign key constraint

No, this will not drop your table if there are indeed foreign keys referencing it. To get all foreign key relationships referencing your table, you could use this SQL (if you’re on SQL Server 2005 and up): SELECT * FROM sys.foreign_keys WHERE referenced_object_id = object_id(‘Student’) and if there are any, with this statement here, you … Read more

Rails DB Migration – How To Drop a Table?

You won’t always be able to simply generate the migration to already have the code you want. You can create an empty migration and then populate it with the code you need. You can find information about how to accomplish different tasks in a migration here: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html More specifically, you can see how to drop … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)