7

Where I can see which default columns SQLite table will have after creating? I need a column with datetime which has default value of time when data added to the table.\

Now I'm trying:

ALTER TABLE recipes ADD COLUMN timestamp DATE DEFAULT (datetime('now','localtime'));

And I'm obtaining the following message:

SQLiteManager: Likely SQL syntax error: ALTER TABLE recipes ADD COLUMN timestamp DATE DEFAULT (datetime('now','localtime')); [ Cannot add a column with non-constant default ]
Exception Name: NS_ERROR_FAILURE
 Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)         [mozIStorageConnection.createStatement]
Stephan
  • 41,764
  • 65
  • 238
  • 329
Stas
  • 1,355
  • 6
  • 22
  • 40
  • `ALTER TABLE` doesn't allow this: "The column may not have a default value of CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP, or an expression in parentheses." https://www.sqlite.org/lang_altertable.html –  Jul 24 '12 at 13:10

1 Answers1

16

Use the create table instead of altering the table. If there are values inside you'll have this kind of a problem. See

http://sqlite.1065341.n5.nabble.com/Can-t-insert-timestamp-field-with-value-CURRENT-TIME-td42729.html

all the best

devanand
  • 5,116
  • 2
  • 20
  • 19