Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFrida F
6,261 PointsError trying to run the create_versions migration
I am getting the following error when I try to run the migration that should create the versions table:
== CreateVersions: migrating =================================================
-- create_table(:versions)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `versions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `item_type` varchar(255) NOT NULL, `item_id` int(11) NOT NULL, `event` varchar(255) NOT NULL, `whodunnit` varchar(255), `object` text, `created_at` datetime)
After the error happened with the newest version of the gem, I have set the paper trail gem to version 3.0.0 to have the migration look exactly like in the tutorial, to no effect. Rails is 4.0.3.
I don't understand why it happens tbh, so if anyone maybe could point me in the right direction please? Thanks everyone!
3 Answers
Steve Hunter
57,712 PointsHi Frida,
That's a tricky one! Can you post the migration file? I can compare it to mine to see if there's any difference but, since it is autogenerated, I suspect it'll be identical. Maybe post your schema too.
What version of MySQL are you using? Hve a look at this post as I think that'll help more than I can!
Steve.
Frida F
6,261 PointsThank you so much, Steve!
The link looks promising. I feel like the issue might be solved if I update my MySQL (5.6.23), so I will now figure out how to do that without blowing everything up. If I understand correctly there has been a patch for this or a similar issue with MySQL 5.7, so maybe updating to 5.7 does the trick. - I am more or less guessing but will update whether that worked or not.
Thank you again!
Steve Hunter
57,712 PointsYes, you're right they patched the release for this issue, from what I read. Good luck applying it! Are you running Windows or Mac? The documentation might help you. Give it a go and it everything goes South shout back and I'll see if I can help.
Steve.
Mike Ulvila
16,268 PointsHey Frida, I removed the options block from the migration file and it works.
def versions_table_options
if MYSQL_ADAPTERS.include?(connection.class.name)
{ options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }
else
{}
end
end