Mateusz Czerwiński Mateusz Czerwiński - 4 months ago 35
Ruby Question

Rake is aborting because undefined method `inet' for sqlite db

My Rails application uses two databases, first is postgresql and second -sqlite, the last for test environment. I used Devise gem which uses inet data type to carring infomation about IP. It works well for postgresql, but couses some errors for sqlite. I had installed a gem postgres_ext and added it to Gemfile, but it didn't solve the problem. Below is a piece of log:

$ RAILS_ENV=test rake db:setup
(in /user/project)
db/test.sqlite3 already exists
-- enable_extension("plpgsql")
-> 0.0030s
-- create_table("comments", {:force=>:cascade})
-> 0.3368s
-- add_index("comments", ["commentable_id"],
{:name=>"index_comments_on_commentable_id", :using=>:btree})
-> 0.1680s
-- add_index("comments", ["commentable_type"], {:name=>"index_comments_on_commentable_type", :using=>:btree})
-> 0.1898s
-- add_index("comments", ["user_id"], {:name=>"index_comments_on_user_id", :using=>:btree})
-> 0.1568s
-- create_table("contacts", {:force=>:cascade})
-> 0.2803s
-- create_table("delayed_jobs", {:force=>:cascade})
-> 0.2818s
-- add_index("delayed_jobs", ["priority", "run_at"], {:name=>"delayed_jobs_priority", :using=>:btree})
-> 0.1677s
-- create_table("exercises", {:force=>:cascade})
-> 0.3360s
-- create_table("languages", {:force=>:cascade})
-> 0.3025s
-- create_table("levels", {:force=>:cascade})
-> 0.2692s
-- create_table("solutions", {:force=>:cascade})
-> 0.3262s
-- create_table("users", {:force=>:cascade})
rake aborted!
NoMethodError: undefined method `inet' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000007563ec8>
/home/mtczerwinski/Projekty/ruby/railsilla/db/schema.rb:104:in `block (2 levels) in <top (required)>'


and so on.

Can you tell me what I am doing wrong ?

Answer

PostgreSQL has a native inet type:

8.9.1. inet

The inet type holds an IPv4 or IPv6 host address, and optionally its subnet, all in one field. [...]

but SQLite doesn't. Apparently your users table has an inet column in it so that part of your schema is PostgreSQL-specific.

Using a different database for testing than you use for development and production is just as bad an idea as using different databases for development and production. ActiveRecord offers very little in the way of portability so switch your test environment to PostgreSQL too.

Comments