Trying to rename a columns of a table in laravel throws error










4















I follow the guide here in modifying the column in Laravel.



I have table stores
and run this in command line



php artisan make:migration rename_stores_column --table="stores" --create



After creating the migration



here the code



class RenameStoresColumn extends Migration

/**
* Run the migrations.
*
* @return void
*/
public function up()

Schema::table('stores', function (Blueprint $table)
$table->renameColumn('store_iamge', 'store_image');
);


/**
* Reverse the migrations.
*
* @return void
*/
public function down()

Schema::table('stores', function (Blueprint $table)
$table->renameColumn('store_image', 'store_iamge');
);




but when i run php artisan migrate



I got this error,



In Connection.php line 664:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists (SQL: create table `stores` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `address` varchar(255) null, `city` varchar(255) null, `zipcode` varc
har(255) null, `country` varchar(255) null, `state` varchar(255) null, `latitude` double(10, 6) not null, `longitude` double(10, 6) not null, `description` text null, `phone` varchar(255) null, `email` varchar(255) null, `fax` varchar(255) null, `web` varchar(255) n
ull, `tags` varchar(255) null, `schedule` varchar(255) null, `store_iamge` varchar(255) null, `marker_image` varchar(255) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci)


In PDOStatement.php line 143:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists


what the proper way?










share|improve this question




























    4















    I follow the guide here in modifying the column in Laravel.



    I have table stores
    and run this in command line



    php artisan make:migration rename_stores_column --table="stores" --create



    After creating the migration



    here the code



    class RenameStoresColumn extends Migration

    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()

    Schema::table('stores', function (Blueprint $table)
    $table->renameColumn('store_iamge', 'store_image');
    );


    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()

    Schema::table('stores', function (Blueprint $table)
    $table->renameColumn('store_image', 'store_iamge');
    );




    but when i run php artisan migrate



    I got this error,



    In Connection.php line 664:

    SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists (SQL: create table `stores` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `address` varchar(255) null, `city` varchar(255) null, `zipcode` varc
    har(255) null, `country` varchar(255) null, `state` varchar(255) null, `latitude` double(10, 6) not null, `longitude` double(10, 6) not null, `description` text null, `phone` varchar(255) null, `email` varchar(255) null, `fax` varchar(255) null, `web` varchar(255) n
    ull, `tags` varchar(255) null, `schedule` varchar(255) null, `store_iamge` varchar(255) null, `marker_image` varchar(255) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci)


    In PDOStatement.php line 143:

    SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists


    what the proper way?










    share|improve this question


























      4












      4








      4








      I follow the guide here in modifying the column in Laravel.



      I have table stores
      and run this in command line



      php artisan make:migration rename_stores_column --table="stores" --create



      After creating the migration



      here the code



      class RenameStoresColumn extends Migration

      /**
      * Run the migrations.
      *
      * @return void
      */
      public function up()

      Schema::table('stores', function (Blueprint $table)
      $table->renameColumn('store_iamge', 'store_image');
      );


      /**
      * Reverse the migrations.
      *
      * @return void
      */
      public function down()

      Schema::table('stores', function (Blueprint $table)
      $table->renameColumn('store_image', 'store_iamge');
      );




      but when i run php artisan migrate



      I got this error,



      In Connection.php line 664:

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists (SQL: create table `stores` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `address` varchar(255) null, `city` varchar(255) null, `zipcode` varc
      har(255) null, `country` varchar(255) null, `state` varchar(255) null, `latitude` double(10, 6) not null, `longitude` double(10, 6) not null, `description` text null, `phone` varchar(255) null, `email` varchar(255) null, `fax` varchar(255) null, `web` varchar(255) n
      ull, `tags` varchar(255) null, `schedule` varchar(255) null, `store_iamge` varchar(255) null, `marker_image` varchar(255) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci)


      In PDOStatement.php line 143:

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists


      what the proper way?










      share|improve this question
















      I follow the guide here in modifying the column in Laravel.



      I have table stores
      and run this in command line



      php artisan make:migration rename_stores_column --table="stores" --create



      After creating the migration



      here the code



      class RenameStoresColumn extends Migration

      /**
      * Run the migrations.
      *
      * @return void
      */
      public function up()

      Schema::table('stores', function (Blueprint $table)
      $table->renameColumn('store_iamge', 'store_image');
      );


      /**
      * Reverse the migrations.
      *
      * @return void
      */
      public function down()

      Schema::table('stores', function (Blueprint $table)
      $table->renameColumn('store_image', 'store_iamge');
      );




      but when i run php artisan migrate



      I got this error,



      In Connection.php line 664:

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists (SQL: create table `stores` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `address` varchar(255) null, `city` varchar(255) null, `zipcode` varc
      har(255) null, `country` varchar(255) null, `state` varchar(255) null, `latitude` double(10, 6) not null, `longitude` double(10, 6) not null, `description` text null, `phone` varchar(255) null, `email` varchar(255) null, `fax` varchar(255) null, `web` varchar(255) n
      ull, `tags` varchar(255) null, `schedule` varchar(255) null, `store_iamge` varchar(255) null, `marker_image` varchar(255) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_unicode_ci)


      In PDOStatement.php line 143:

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'stores' already exists


      what the proper way?







      php laravel






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 5:52









      Cœur

      19k9113154




      19k9113154










      asked May 2 '18 at 6:47









      FilFil

      1,49542340




      1,49542340






















          2 Answers
          2






          active

          oldest

          votes


















          1














          It doesn't seem that your issue has anything to do with this rename_stores_column migration. It looks like php artisan migrate tries to rerun the create_stores_table migration even though it was already run.



          Now you may come across this issue easily if at any point you have an error in one of your migrations, because the migration runs, it creates the table, but then the error occurs, the batch fails and it doesn't manage to insert the name of the migration in migrations table, so at the next migrate it will run it again, thus the issue you have here.



          To solve this, you either run a fresh migrate (php artisan migrate:fresh) but only if you are on a dev environment and don't have any data to lose.



          Or, in create_stores_table migration wrap the schema create in a schema has, so even if it tries to run it, if the table already exists it won't do anything:



          if (!Schema::hasTable('stores')) 
          Schema::create('stores', function (Blueprint $table)
          $table->increments('id');

          ...
          );






          share|improve this answer


















          • 1





            Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

            – Fil
            May 2 '18 at 8:31


















          2














          Did you require doctrine/dbal?




          Prerequisites



          Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:




          composer require doctrine/dbal





          share|improve this answer























          • yes already have

            – Fil
            May 2 '18 at 6:56






          • 2





            The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

            – Douwe de Haan
            May 2 '18 at 7:00










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50128626%2ftrying-to-rename-a-columns-of-a-table-in-laravel-throws-error%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          It doesn't seem that your issue has anything to do with this rename_stores_column migration. It looks like php artisan migrate tries to rerun the create_stores_table migration even though it was already run.



          Now you may come across this issue easily if at any point you have an error in one of your migrations, because the migration runs, it creates the table, but then the error occurs, the batch fails and it doesn't manage to insert the name of the migration in migrations table, so at the next migrate it will run it again, thus the issue you have here.



          To solve this, you either run a fresh migrate (php artisan migrate:fresh) but only if you are on a dev environment and don't have any data to lose.



          Or, in create_stores_table migration wrap the schema create in a schema has, so even if it tries to run it, if the table already exists it won't do anything:



          if (!Schema::hasTable('stores')) 
          Schema::create('stores', function (Blueprint $table)
          $table->increments('id');

          ...
          );






          share|improve this answer


















          • 1





            Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

            – Fil
            May 2 '18 at 8:31















          1














          It doesn't seem that your issue has anything to do with this rename_stores_column migration. It looks like php artisan migrate tries to rerun the create_stores_table migration even though it was already run.



          Now you may come across this issue easily if at any point you have an error in one of your migrations, because the migration runs, it creates the table, but then the error occurs, the batch fails and it doesn't manage to insert the name of the migration in migrations table, so at the next migrate it will run it again, thus the issue you have here.



          To solve this, you either run a fresh migrate (php artisan migrate:fresh) but only if you are on a dev environment and don't have any data to lose.



          Or, in create_stores_table migration wrap the schema create in a schema has, so even if it tries to run it, if the table already exists it won't do anything:



          if (!Schema::hasTable('stores')) 
          Schema::create('stores', function (Blueprint $table)
          $table->increments('id');

          ...
          );






          share|improve this answer


















          • 1





            Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

            – Fil
            May 2 '18 at 8:31













          1












          1








          1







          It doesn't seem that your issue has anything to do with this rename_stores_column migration. It looks like php artisan migrate tries to rerun the create_stores_table migration even though it was already run.



          Now you may come across this issue easily if at any point you have an error in one of your migrations, because the migration runs, it creates the table, but then the error occurs, the batch fails and it doesn't manage to insert the name of the migration in migrations table, so at the next migrate it will run it again, thus the issue you have here.



          To solve this, you either run a fresh migrate (php artisan migrate:fresh) but only if you are on a dev environment and don't have any data to lose.



          Or, in create_stores_table migration wrap the schema create in a schema has, so even if it tries to run it, if the table already exists it won't do anything:



          if (!Schema::hasTable('stores')) 
          Schema::create('stores', function (Blueprint $table)
          $table->increments('id');

          ...
          );






          share|improve this answer













          It doesn't seem that your issue has anything to do with this rename_stores_column migration. It looks like php artisan migrate tries to rerun the create_stores_table migration even though it was already run.



          Now you may come across this issue easily if at any point you have an error in one of your migrations, because the migration runs, it creates the table, but then the error occurs, the batch fails and it doesn't manage to insert the name of the migration in migrations table, so at the next migrate it will run it again, thus the issue you have here.



          To solve this, you either run a fresh migrate (php artisan migrate:fresh) but only if you are on a dev environment and don't have any data to lose.



          Or, in create_stores_table migration wrap the schema create in a schema has, so even if it tries to run it, if the table already exists it won't do anything:



          if (!Schema::hasTable('stores')) 
          Schema::create('stores', function (Blueprint $table)
          $table->increments('id');

          ...
          );







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 2 '18 at 7:53









          igs013igs013

          731414




          731414







          • 1





            Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

            – Fil
            May 2 '18 at 8:31












          • 1





            Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

            – Fil
            May 2 '18 at 8:31







          1




          1





          Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

          – Fil
          May 2 '18 at 8:31





          Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment

          – Fil
          May 2 '18 at 8:31













          2














          Did you require doctrine/dbal?




          Prerequisites



          Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:




          composer require doctrine/dbal





          share|improve this answer























          • yes already have

            – Fil
            May 2 '18 at 6:56






          • 2





            The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

            – Douwe de Haan
            May 2 '18 at 7:00















          2














          Did you require doctrine/dbal?




          Prerequisites



          Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:




          composer require doctrine/dbal





          share|improve this answer























          • yes already have

            – Fil
            May 2 '18 at 6:56






          • 2





            The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

            – Douwe de Haan
            May 2 '18 at 7:00













          2












          2








          2







          Did you require doctrine/dbal?




          Prerequisites



          Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:




          composer require doctrine/dbal





          share|improve this answer













          Did you require doctrine/dbal?




          Prerequisites



          Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:




          composer require doctrine/dbal






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 2 '18 at 6:49









          Douwe de HaanDouwe de Haan

          3,45811428




          3,45811428












          • yes already have

            – Fil
            May 2 '18 at 6:56






          • 2





            The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

            – Douwe de Haan
            May 2 '18 at 7:00

















          • yes already have

            – Fil
            May 2 '18 at 6:56






          • 2





            The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

            – Douwe de Haan
            May 2 '18 at 7:00
















          yes already have

          – Fil
          May 2 '18 at 6:56





          yes already have

          – Fil
          May 2 '18 at 6:56




          2




          2





          The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

          – Douwe de Haan
          May 2 '18 at 7:00





          The other option is that there are multiple migrations which try to create (Schema::create) the stores` table. Could you verify this?

          – Douwe de Haan
          May 2 '18 at 7:00

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50128626%2ftrying-to-rename-a-columns-of-a-table-in-laravel-throws-error%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế