{"ok": true, "next": null, "rows": [{"id": "json_api:tablecreateview", "page": "json_api", "ref": "tablecreateview", "title": "Creating a table", "content": "To create a table, make a  POST  to  /<database>/-/create . This requires the  create-table  permission. \n                 POST /<database>/-/create\nContent-Type: application/json\nAuthorization: Bearer dstok_<rest-of-token> \n                 {\n    \"table\": \"name_of_new_table\",\n    \"columns\": [\n        {\n            \"name\": \"id\",\n            \"type\": \"integer\"\n        },\n        {\n            \"name\": \"title\",\n            \"type\": \"text\",\n            \"not_null\": true,\n            \"default\": \"Untitled\"\n        },\n        {\n            \"name\": \"created\",\n            \"type\": \"text\",\n            \"default_expr\": \"current_timestamp\"\n        }\n    ],\n    \"pk\": \"id\"\n} \n                 The JSON here describes the table that will be created: \n                 \n                     \n                         table  is the name of the table to create. This field is required. \n                     \n                     \n                         columns  is a list of columns to create. Each column is a dictionary with  name  and  type  keys. \n                         \n                             \n                                 name  is the name of the column. This is required. \n                             \n                             \n                                 type  is the type of the column. This is optional - if not provided,  text  will be assumed. The valid types are  text ,  integer ,  float  and  blob . \n                             \n                             \n                                 not_null  can be set to  true  to create this column with a  NOT NULL  constraint. \n                             \n                             \n                                 default  can be used to set a literal default value for this column. \n                             \n                             \n                                 default_expr  can be used instead of  default  to set a SQLite default expression. See  default_expr values . \n                             \n                             \n                                 fk_table  can be used to create a single-column foreign key constraint referencing another table.  fk_column  is optional and can be used to specify the referenced column - if omitted, Datasette will use the single primary key of  fk_table . \n                             \n                         \n                     \n                     \n                         pk  is the primary key for the table. This is optional - if not provided, Datasette will create a SQLite table with a hidden  rowid  column. \n                         If the primary key is an integer column, it will be configured to automatically increment for each new record. \n                         If you set this to  id  without including an  id  column in the list of  columns , Datasette will create an auto-incrementing integer ID column for you. \n                     \n                     \n                         pks  can be used instead of  pk  to create a compound primary key. It should be a JSON list of column names to use in that primary key. \n                     \n                     \n                         ignore  can be set to  true  to ignore existing rows by primary key if the table already exists. \n                     \n                     \n                         replace  can be set to  true  to replace existing rows by primary key if the table already exists. This requires the  update-row  permission. \n                     \n                     \n                         alter  can be set to  true  if you want to automatically add any missing columns to the table. This requires the  alter-table  permission. \n                     \n                 \n                 \n                 default_expr  accepts these values: \n                 \n                     \n                         \n                         \n                         \n                         \n                             \n                                 \n                                     Value \n                                 \n                                 \n                                     Recommended column type \n                                 \n                                 \n                                     Example inserted value \n                                 \n                             \n                         \n                         \n                             \n                                 \n                                     current_timestamp \n                                 \n                                 \n                                     text \n                                 \n                                 \n                                     2026-05-01 13:34:00 \n                                 \n                             \n                             \n                                 \n                                     current_date \n                                 \n                                 \n                                     text \n                                 \n                                 \n                                     2026-05-01 \n                                 \n                             \n                             \n                                 \n                                     current_time \n                                 \n                                 \n                                     text \n                                 \n                                 \n                                     13:34:00 \n                                 \n                             \n                             \n                                 \n                                     current_unixtime \n                                 \n                                 \n                                     integer \n                                 \n                                 \n                                     1777642440 \n                                 \n                             \n                             \n                                 \n                                     current_unixtime_ms \n                                 \n                                 \n                                     integer \n                                 \n                                 \n                                     1777642440000 \n                                 \n                             \n                         \n                     \n                 \n                 This example creates a foreign key from  projects.owner_id  to the single primary key of  owners : \n                 {\n    \"table\": \"projects\",\n    \"columns\": [\n        {\n            \"name\": \"id\",\n            \"type\": \"integer\"\n        },\n        {\n            \"name\": \"owner_id\",\n            \"type\": \"integer\",\n            \"fk_table\": \"owners\"\n        },\n        {\n            \"name\": \"title\",\n            \"type\": \"text\"\n        }\n    ],\n    \"pk\": \"id\"\n} \n                 If the table is successfully created this will return a  201  status code and the following response: \n                 {\n    \"ok\": true,\n    \"database\": \"data\",\n    \"table\": \"name_of_new_table\",\n    \"table_url\": \"http://127.0.0.1:8001/data/name_of_new_table\",\n    \"table_api_url\": \"http://127.0.0.1:8001/data/name_of_new_table.json\",\n    \"schema\": \"CREATE TABLE [name_of_new_table] (\\n   [id] INTEGER PRIMARY KEY,\\n   [title] TEXT NOT NULL DEFAULT 'Untitled',\\n   [created] TEXT DEFAULT CURRENT_TIMESTAMP\\n)\"\n}", "breadcrumbs": "[\"JSON API\", \"The JSON write API\"]", "references": "[]"}], "truncated": false}