Skip to content
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

rake db:migrate does not work #703

Closed
kaustubh-nair opened this issue Jun 16, 2019 · 11 comments · Fixed by #959
Closed

rake db:migrate does not work #703

kaustubh-nair opened this issue Jun 16, 2019 · 11 comments · Fixed by #959

Comments

@kaustubh-nair
Copy link
Member

While running migrations for the first time, the migrations fail. A workaround for this is to use rake db:setup but it's a good idea to have clean migration files.

== 20091016214109 CreateMaps: migrating =======================================
-- create_table(:maps)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: BLOB, TEXT, GEOMETRY or JSON column 'styles' can't have a default value: CREATE TABLE `maps` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT '', `lat` decimal(20,10) DEFAULT 0, `lon` decimal(20,10) DEFAULT 0, `zoom` decimal DEFAULT 0.02, `version` int(11) DEFAULT 1, `password` varchar(255) DEFAULT '', `styles` text DEFAULT '', `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
/h
@alaxalves
Copy link
Member

Is this on main branch?

@kaustubh-nair
Copy link
Member Author

kaustubh-nair commented Jun 17, 2019 via email

@alaxalves
Copy link
Member

Weird, so this might be coming from main.

@kaustubh-nair
Copy link
Member Author

I think the problem here is with some specific migration file. Because here I can run db:migrate after deleting all the migrations. But it doesn't work on rails-5

@cesswairimu
Copy link
Collaborator

Which branch could I pull to replicate this? @alaxalves

@kaustubh-nair
Copy link
Member Author

Hi @cesswairimu
This is a problem on the main branch

@alaxalves
Copy link
Member

Has this been fixed? @kaustubh-nair @cesswairimu

@jywarren
Copy link
Member

jywarren commented Jul 8, 2019

Hi all, what's the latest with this? Thank you!

@grvsachdeva
Copy link
Member

Solved in #891. @kaustubh-nair @alaxalves please verify. Thank you!

@kaustubh-nair
Copy link
Member Author

Reopening this because I'm still facing this. The error is the same as mentioned above
I think there is something wrong with the create_maps migration? To reproduce it, drop database, create it, and run migrations
@publiclab/mapknitter-reviewers

@sashadev-sky sashadev-sky mentioned this issue Sep 5, 2019
7 tasks
@jywarren
Copy link
Member

jywarren commented Sep 5, 2019

Aha, so @sashadev-sky was addressing this in #959 but actually we should not edit migrations in the past -- they're kind of like version tracking... and any migration already run on a live instance of the app should be considered permanent. Any changes should be added to a new migration - which is why they have timestamps. Does that make sense? So that means these changes to old migrations will cause trouble in any live instance of the app:

https://github.com/publiclab/mapknitter/pull/959/files#diff-1bb55a2824cab57e594057f2563e58a9L8

But! There is a solution. We can add/remove defaults and make changes using this syntax:

https://github.com/publiclab/plots2/blob/b6d5089c5ac3b80ef48481a6753f39b8dc0812ca/db/migrate/20180220180926_add_default_value_to_comment_status.rb#L3

So, instead of those migration changes, let's make all the necessary changes in a new migration with a new timestamp. Then people will be able to build a dev database from it with rake db:setup.

Does that work for folks? Thank you!

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

Successfully merging a pull request may close this issue.

5 participants