fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
284 stars 31 forks source link

Feature: migration, not null constraint failed: provide default? #109

Open vindarel opened 2 years ago

vindarel commented 2 years ago

Hi,

Say I add a field to my model:

(due-date
    :col-type :timestamp
    :initform (local-time:timestamp+ (local-time:now) 60 :days)
    :accessor due-date)

When I run Mito's migrations, I get

Error while resetting an sqlite statement.
Code CONSTRAINT: NOT NULL constraint failed: contact_copies.due_date.
Database: /home/vince/projets/openbookstore/openbookstore/db.db
SQL: INSERT INTO "contact_copies" ("book_id", "contact_id", "created_at", "id", "max_time", "quantity", "updated_at") SELECT "book_id", "contact_id", "created_at", "id", "max_time", "quantity", "updated_at" FROM "contact_copies1414"

Solution 1: I could change the col type and make it be (or :null :timestamp).

Wouldn't it be nice if we had a restart that asked for a default, or maybe even use the initform as a default?

fukamachi commented 2 years ago

I think it works on MySQL/PostgreSQL, but seems not on SQLite3. Should be fixed.

zen-wq commented 2 years ago

Should be fixed by https://github.com/fukamachi/mito/pull/97 Not in quicklisp yet.