Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Drop views and tables

I have a migration that create a view in MySQL. when I run

PHP artisan db:wipe

it drops all the tables but not the view.

when I run

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

php artisan migrate

it says base table or view already exists.

my migration

    public function up()
    {
        DB::statement("
            CREATE VIEW contacts_view 
            AS
            SELECT
            *
            FROM
                accounts
            where isContact='yes';
        ");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Schema::dropIfExists('contacts_view');
        DB::statement("DROP VIEW contacts_view");
    }

>Solution :

To avoid errors when running your migration with existing view, sue CREATE OR REPLACE

public function up()
{
    DB::statement("
        CREATE OR REPLACE VIEW contacts_view 
        AS
        SELECT
        *
        FROM
            accounts
        where isContact='yes';
    ");
}

The view will always be recreated.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading