On Saturday, August 12, 2017 at 11:21:37 AM UTC-7, Sergey Kislyakov wrote:
>
>
> I have a very simple database structure in my project that looks like that:
> # /db/migrate/001_create_posts.rb
> Sequel.migration do
>   change do
>     create_table :posts do
>       primary_key :id
>         
>       String    :title,       null: false
>       String    :description, null: false
>       String    :body,        null: false, text: true
>       TrueClass :published,   null: false, default: true
>     end
>   end
> end
>
> # /db/database.rb
>
> module DB
>   Connection = Sequel.sqlite('database.rb')
>

You are naming the database database.rb here.  You probably want to use 
database.db to match the migration file name used below.
 

>
> end
>
> class Post < Sequel::Model
> end
>
> I've did 
> bundle exec sequel -m db/migrate db/database.db
>
> Here is where you are creating the posts table in a database.db file.
 

> It worked and I can access the table using 
> DB::Connection[:posts]
>

Note that this just creates a dataset, it doesn't actually run code on the 
database or make sure the posts table exists.
 

> However, when I'm trying to run the `database.rb` file, I get this warning:
>
> SEQUEL DEPRECATION WARNING: Setting a model class dataset to an invalid 
> dataset is deprecated and will be removed in Sequel 5.  Either use a 
> valid dataset or set require_valid_table = false for the model class.
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/
> lib/sequel/model/base.rb:1008:in `rescue in check_non_connection_error'
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/lib/sequel/model/base.rb:1001:in
>  
> `check_non_connection_error'
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/lib/sequel/model/base.rb:1123:in
>  
> `block in get_db_schema'
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/
> lib/sequel/model/base.rb:1156:in `get_db_schema'
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/lib/sequel/model/base.rb:893:in
>  
> `set_dataset'
> /home/defman/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sequel-4.49.0/lib/sequel/model/base.rb:704:in
>  
> `inherited'
> db/database.rb:5:in `<main>'
>
> Is there something I need to change? I've spent my whole day trying to 
> find why I get the warning, no luck.
>

This is Sequel correctly warning that you created a Post model where the 
underlying table (posts) does not actually exist in the database.  If it 
didn't warn now (and raise an error in Sequel 5), it would definitely fail 
later when you actually tried to use the model.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to