A
A
Albert Tobacco2015-04-27 17:38:16
Yii
Albert Tobacco, 2015-04-27 17:38:16

How to catch errors when performing a migration via $this->execute(); yii2?

I want to use raw SQL

public function up()
    {
        $sql = <<<SQL
CREATE TABLE .....
SQL;

        try{
            $this->execute($sql);
        }catch (\yii\base\Exception $e){
            echo $e->getMessage();
            return false;
        }

    }

This is how I try to catch errors. Sometimes they are caught, sometimes they are not :(. It can easily omit an error from FOREIGN KEY registration, for example. How to catch all errors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-04-27
@miraage

Yii2 Docs: Transactional Migrations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question