0

I use laravel migartion to create some tables and then i create a migration for a view that use my tables. now, i want to change type of column that used in this view (i create a new migration for it.).but, PostgreSQL does not let me to change column type because column is used in view. i want to know what is best way to manage this issue.

i tried to use migration that created view to drop then and recreate it after changing column type but there is problem because migrations doesn't have namespaces and i don't know is it good way for solving this problem.

2 Answers 2

0

First, my English is not good. What i understand is, you are creating a new migration with already existing table? If the table is already existed then you may try to change the column name using this

Schema::table('users', function (Blueprint $table) {
    $table->string('name', 50)->change();
});

Laravel Documentation

1
  • no, it's not my answer. i know how change column type i want a good way for solve column dependencies error before changing type. May 18, 2020 at 7:44
0

I fix my issue with following level:

  1. add folder common-queries in project/database/migrations/

  2. add CommonQueries namespace in composer.json with project/database/migrations/common-queries folder location.

  3. add my view create and drop in a class MyCurrentView (for example).

  4. use this class in old migration up and down function for creating and droping view

  5. use this class in new migration and drop view before changing column type and create view after changing column type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.