How to alter a database table?

sql
db-alter-table
database
db-table
(Dmitry Fedyuk) #1

There are ready methods for some popular alterations:

If you need a custom alteration then use the query() and resetDdlCache() methods of the \Magento\Framework\DB\Adapter\AdapterInterface:


An example from the core:

By default the \Magento\Framework\DB\Adapter\AdapterInterface interface is implemented by the \Magento\Framework\DB\Adapter\Pdo\Mysql class:

When you have a \Magento\Framework\DB\Adapter\Pdo\Mysql instance you can also use rawQuery() method instead of query() (rawQuery() method is absent in the \Magento\Framework\DB\Adapter\AdapterInterface):


0 Likes

How to change (modify) a column definition for a database table
How to add an index to a database table
How to delete (drop) a column from a database table?
How to rename a database column?
How to delete (drop) a foreign key from a database table
How to add a column to a database table?
How to add a foreign key to a database table
How to delete (drop) an index from a database table
How to rename a database table
(Dmitry Fedyuk) #2

See also:

0 Likes