New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop and add column of a table in one migration #2694

Closed
skarolus opened this Issue Nov 11, 2013 · 15 comments

Comments

Projects
None yet
@skarolus

skarolus commented Nov 11, 2013

Hi,

i have following issue:

When i am running the seeder

with the structure:

array (
        'address_id'         => 1,
        'userName'            => 'testUser'
    ),

and the migration:

public function up()
{
    Schema::table('users_models', function($table)
        {
            $table->dropColumn('secondName', 'hairColor');
            $table->integer('address_id')->unsigned();
        });
}

there is the error message:

table users_models has no column named address_id

I am using

  • sqlite
  • Laravel Framework version 4.0.6

When I split the migration, it works

public function up()
{
        Schema::table('users_models', function($table)
        {
            $table->dropColumn('secondName', 'hairColor');
        });

        Schema::table('users_models', function($table)
        {
            $table->integer('address_id')->unsigned();
        });
}

@robclancy

This comment has been minimized.

Show comment
Hide comment
@robclancy

robclancy Nov 11, 2013

Contributor

That's weird. What happens if you put the integer stuff before dropping the column in the first example?

Also those should be 2 completely separate migrations anyway.

Contributor

robclancy commented Nov 11, 2013

That's weird. What happens if you put the integer stuff before dropping the column in the first example?

Also those should be 2 completely separate migrations anyway.

@skarolus

This comment has been minimized.

Show comment
Hide comment
@skarolus

skarolus Nov 11, 2013

The same error occurres.

skarolus commented Nov 11, 2013

The same error occurres.

@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Nov 11, 2013

Member

I would just use the work-around then. Probably has something to do with how the SQLite table is dropped when dropping columns because of SQLite limitations.

Member

taylorotwell commented Nov 11, 2013

I would just use the work-around then. Probably has something to do with how the SQLite table is dropped when dropping columns because of SQLite limitations.

@schickling

This comment has been minimized.

Show comment
Hide comment
@schickling

schickling Nov 12, 2013

Hmm same issue here. Feels kinda odd to use the workaround...

schickling commented Nov 12, 2013

Hmm same issue here. Feels kinda odd to use the workaround...

@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Nov 12, 2013

Member

Just use the workaround. You're using the most expressive migration builder ever written in PHP for crying out loud.


Sent from Mailbox for iPhone

On Tue, Nov 12, 2013 at 2:55 AM, Johannes Schickling
notifications@github.com wrote:

Hmm same issue here. Feels kinda odd to use the workaround...

Reply to this email directly or view it on GitHub:
#2694 (comment)

Member

taylorotwell commented Nov 12, 2013

Just use the workaround. You're using the most expressive migration builder ever written in PHP for crying out loud.


Sent from Mailbox for iPhone

On Tue, Nov 12, 2013 at 2:55 AM, Johannes Schickling
notifications@github.com wrote:

Hmm same issue here. Feels kinda odd to use the workaround...

Reply to this email directly or view it on GitHub:
#2694 (comment)

@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell
Member

taylorotwell commented Nov 12, 2013

😄

joshuajabbour added a commit to joshuajabbour/sentry that referenced this issue Jan 25, 2014

joshuajabbour added a commit to joshuajabbour/sentry that referenced this issue Jan 25, 2014

joshuajabbour added a commit to joshuajabbour/sentry that referenced this issue Jan 25, 2014

Fix "alter_groups" migration for sqlite.
Split table actions. Ensure not null column default isn't null.

See laravel/framework#2694.
@michel-slm

This comment has been minimized.

Show comment
Hide comment
@michel-slm

michel-slm Feb 25, 2014

Same here, was tearing my hair out until I found this bug report. Will try splitting the migration for now until there's a stable release

michel-slm commented Feb 25, 2014

Same here, was tearing my hair out until I found this bug report. Will try splitting the migration for now until there's a stable release

@joshuajabbour

This comment has been minimized.

Show comment
Hide comment
@joshuajabbour

joshuajabbour Feb 25, 2014

Contributor

Just to be clear, the problem with the "workaround" is that it makes using packages with migrations completely unreliable. So package developers need to test on all supported databases, which they don't. Therefore, any developer using an alternative DB needs to test and fix any packages they use, in the process figuring out this confusing and non-obvious bug.

Contributor

joshuajabbour commented Feb 25, 2014

Just to be clear, the problem with the "workaround" is that it makes using packages with migrations completely unreliable. So package developers need to test on all supported databases, which they don't. Therefore, any developer using an alternative DB needs to test and fix any packages they use, in the process figuring out this confusing and non-obvious bug.

GenPage added a commit to TechnicPack/TechnicSolder that referenced this issue Dec 24, 2014

Fix SQLite issues once and for all, Setup pre-populated SQLite DB for…
… hands-free app installation

- SQLite does not like multiple dropColumns() in one Schema call (laravel/framework#2694)
- Update default SQLite server to 'sqlite'
- Update pre-seeded sqlite file with latest migrations
@stewartadam

This comment has been minimized.

Show comment
Hide comment
@stewartadam

stewartadam Jan 13, 2015

I just ran into this as well, it's really silly:

  • You cannot add columns and drop columns in the same migration
  • You cannot have multiple column drops in the same migration

It would appear it's okay with multiple renames though. The workaround is good to know, but the root cause should really be resolved.

stewartadam commented Jan 13, 2015

I just ran into this as well, it's really silly:

  • You cannot add columns and drop columns in the same migration
  • You cannot have multiple column drops in the same migration

It would appear it's okay with multiple renames though. The workaround is good to know, but the root cause should really be resolved.

@reinink

This comment has been minimized.

Show comment
Hide comment
@reinink

reinink Jun 11, 2015

Contributor

For anyone else who runs into this issue, @stewartadam is correct, breaking the migrations up seems to solve it. I had this problem when I added two columns in the same migrations.

Contributor

reinink commented Jun 11, 2015

For anyone else who runs into this issue, @stewartadam is correct, breaking the migrations up seems to solve it. I had this problem when I added two columns in the same migrations.

GenPage added a commit to TechnicPack/TechnicSolder that referenced this issue Sep 6, 2015

Fix SQLite issues once and for all, Setup pre-populated SQLite DB for…
… hands-free app installation

- SQLite does not like multiple dropColumns() in one Schema call (laravel/framework#2694)
- Update default SQLite server to 'sqlite'
- Update pre-seeded sqlite file with latest migrations
@erikhu

This comment has been minimized.

Show comment
Hide comment
@erikhu

erikhu Jan 20, 2016

hi i have a problem , when i migrate , its ok the tables but the fields no found , namely the colums no be , thnks somebody can helpme

erikhu commented Jan 20, 2016

hi i have a problem , when i migrate , its ok the tables but the fields no found , namely the colums no be , thnks somebody can helpme

@stewartadam

This comment has been minimized.

Show comment
Hide comment
@stewartadam

stewartadam Jan 20, 2016

@erikhu: the GitHub issue tracker is for reporting bugs in Laravel, for user support or troubleshooting please try a forum such as the one on laravel.io. Remember to be specific in the error you are receiving and what you have tried so far so that the community can best try to assist you in identifying the problem!

stewartadam commented Jan 20, 2016

@erikhu: the GitHub issue tracker is for reporting bugs in Laravel, for user support or troubleshooting please try a forum such as the one on laravel.io. Remember to be specific in the error you are receiving and what you have tried so far so that the community can best try to assist you in identifying the problem!

@erikhu

This comment has been minimized.

Show comment
Hide comment
@erikhu

erikhu Jan 21, 2016

@stewartadam thnks for the reply , i was solved my problem

erikhu commented Jan 21, 2016

@stewartadam thnks for the reply , i was solved my problem

@MikeHopley

This comment has been minimized.

Show comment
Hide comment
@MikeHopley

MikeHopley Jun 27, 2016

I ran into this bug today and was baffled for hours.

The workaround is fine. The problem is knowing about the workaround in the first place. As mentioned above, this is a landmine for packages too. This issue is not even mentioned in the Laravel docs.

This is really unfortunate. Expressive APIs are great, but not when they hide very unexpected buggy behaviour. Sqlite is widely used in the Laravel community for testing databases. This is a nasty case of leaky abstraction.

MikeHopley commented Jun 27, 2016

I ran into this bug today and was baffled for hours.

The workaround is fine. The problem is knowing about the workaround in the first place. As mentioned above, this is a landmine for packages too. This issue is not even mentioned in the Laravel docs.

This is really unfortunate. Expressive APIs are great, but not when they hide very unexpected buggy behaviour. Sqlite is widely used in the Laravel community for testing databases. This is a nasty case of leaky abstraction.

@denismarinov

This comment has been minimized.

Show comment
Hide comment
@denismarinov

denismarinov Jan 8, 2018

Well, what do we do if I have to modify 30+ columns. This workaround is just stupidly redundant.

denismarinov commented Jan 8, 2018

Well, what do we do if I have to modify 30+ columns. This workaround is just stupidly redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment