volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

SQLite3 Issue #367

Closed shazbert closed 6 years ago

shazbert commented 6 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

v3.0.0rc10

using driver:

import _ "github.com/mattn/go-sqlite3"

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE bank_account_config (
  id integer NOT NULL PRIMARY KEY,
  bank_name text NOT NULL,
  bank_address text NOT NULL,
  account_name text NOT NULL,
  account_number text NOT NULL,
  is_exchange_bank boolean NOT NULL,
  swift_code text,
  iban text,
  bsb_number text,
  supported_currencies text NOT NULL,
  supported_exchanges text,
  config_id int NOT NULL
);

Further information. What did you do, what did you expect?

What I did;

func (o *ORM) InsertSomething() error {
    baInsterTest := &models.BankAccountConfig{
        BankName:            "something",
        BankAddress:         "something else",
        AccountName:         "bla",
        AccountNumber:       "blabla",
        IsExchangeBank:      false,
        SupportedCurrencies: "ABC123",
        ConfigID:            1337,
    }
    return baInsterTest.Insert(context.Background(), o.DB, boil.Infer())
}

Intial insert works but then a subsequent insert causes; AUTOINCREMENT not working:

2018/08/13 09:16:12 Opening connection to database....
--- FAIL: TestInsertSomething (0.00s)
    database_test.go:47: Something happened :( models: unable to insert into bank_account_config: UNIQUE constraint failed: bank_account_config.id
FAIL
aarondl commented 6 years ago

Fixed. Thanks for the report. sqlite3 is odd. Also if you haven't already I suggest you read the documentation here https://www.sqlite.org/autoinc.html and ensure that you don't want to be using the AUTOINCREMENT keyword. You probably don't, but it's something you should be making a concious decision about.

shazbert commented 6 years ago

@aarondl Thanks heaps!