I'm trying to check for the existence of a table before dropping it. I've read through the API documentation for Doctrine_Table and I can't seem to find anything like this. Is there something I'm missing?
I've got code that looks like:
$table = new Doctrine_Table('model_name', $conn);
$export = new Doctrine_Export();
$export->dropTable($table->getTableName());
And the error I get when a table doesn't exist is:
Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table
Thanks in advance,
Casey
Doctrine2 method is:
$schemaManager = $this->getDoctrine()->getConnection()->getSchemaManager();
if ($schemaManager->tablesExist(array('users')) == true) {
// table exists! ...
}
Try this for table exist check:
public function up(Schema $schema): void
{
$schema->hasTable('table_name');
}
For columns check:
$schema->getTable('supply')->hasColumn('contracts')
Full example with skip:
$this->skipIf($schema->getTable('supply')->hasColumn('contracts'), 'Table order_statuses already exist');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With