Trying to rename a columns of a table in laravel throws error
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
add a comment |
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
add a comment |
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
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
php laravel
edited Nov 13 '18 at 5:52
Cœur
19k9113154
19k9113154
asked May 2 '18 at 6:47
FilFil
1,49542340
1,49542340
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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');
...
);
1
Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment
– Fil
May 2 '18 at 8:31
add a comment |
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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');
...
);
1
Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment
– Fil
May 2 '18 at 8:31
add a comment |
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');
...
);
1
Thanks man, it works, php artisan migrate:fresh no worries.. i'm in dev environment
– Fil
May 2 '18 at 8:31
add a comment |
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');
...
);
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');
...
);
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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