On May 5, 4:34 am, fairchild <[email protected]> wrote:
> Using sequel 3.0.0
> I thought the following simple code would work, but it fails with
> Sequel::Error: Record not found
> <code>
> require 'rubygems'
> require 'sequel'
>
> DB = Sequel.sqlite
> DB.create_table(:instances) do
>   String :id, :primary_key=>true
>   String :name
> end
>
> class Instance < Sequel::Model
> end
>
> new_inst = Instance.create(:name=>'joe')
> </code>
>
> http://gist.github.com/106937
> <script src="http://gist.github.com/106937.js";></script>

The SQLite adapter doesn't support that.

When you think about what you are doing, it doesn't make sense.  If
you are saying a column is the primary key, it must be both unique and
NOT NULL.  You are trying to insert a record into a table with a NULL
primary key value (and no default/autoincrementing primary key
value).  In other databases that would raise an error.  SQLite
apparently doesn't raise an error, and allows NULL values in primary
key fields.

You have to use an Integer primary key:

  DB.create_table(:instances) do
    primary_key :id
    String :name
  end

It should work fine if you do that.

Note that you can use a string primary key, but then you have to
provide a primary key value:

  new_inst = Instance.create(:name=>'joe', :id=>'blah')

That works fine too.  The problem is that if you don't provide a value
for the string primary key, Sequel is going to refresh the record
assuming that the last insert id is the primary key.  That works fine
for integer primary keys in SQLite, but not string primary keys.

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to