Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why database migration fails in case of blob datatype in rails?

I'm trying to create a simple application with ruby in rails. I've created this scaffold:

rails generate scaffold Pic title:string content:blob description:text

and when I try to migrate db with rake db:migrate I'm getting this error:

rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `blob' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0xb74f8ec4>

When I write say text instead of blob it works normally. So what's the problem with blob ?

like image 505
shift66 Avatar asked Feb 24 '12 13:02

shift66


People also ask

How rails db Migrate works?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.

How do I migrate a database in Ruby on Rails?

Go to db/migrate subdirectory of your application and edit each file one by one using any simple text editor. The ID column will be created automatically, so don't do it here as well. The method self. up is used when migrating to a new version, self.

What is are the default column columns that rails will generate while migrating?

By default, the generated migration will include t. timestamps (which creates the updated_at and created_at columns that are automatically populated by Active Record).

Which command is true to rollback migration in rails?

You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.


2 Answers

The keyword is binary, not blob.

rails generate scaffold Pic title:string content:binary description:text
like image 103
Dave Isaacs Avatar answered Sep 23 '22 15:09

Dave Isaacs


There is no keyword blob in rails, you need binary.

rails generate scaffold Pic title:string content:binary description:text
like image 37
Mikhail Nikalyukin Avatar answered Sep 24 '22 15:09

Mikhail Nikalyukin