Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALTER COLUMN in sqlite

Tags:

sqlite

How do I alter column in sqlite? This is in Postgresql

ALTER TABLE books_book ALTER COLUMN publication_date DROP NOT NULL; 

I believe there is no ALTER COLUMN in sqlite at all, only ALTER TABLE is supported.

Any idea? Thanks!

like image 589
CppLearner Avatar asked Oct 24 '10 03:10

CppLearner


People also ask

Does ALTER TABLE work in SQLite?

Overview. SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows these alterations of an existing table: it can be renamed; a column can be renamed; a column can be added to it; or a column can be dropped from it.

How do I alter a table in SQLite?

Summary. Use the ALTER TABLE statement to modify the structure of an existing table. Use ALTER TABLE table_name RENAME TO new_name statement to rename a table. Use ALTER TABLE table_name ADD COLUMN column_definition statement to add a column to a table.


1 Answers

There's no ALTER COLUMN in sqlite.

I believe your only option is to:

  • Rename the table to a temporary name
  • Create a new table without the NOT NULL constraint
  • Copy the content of the old table to the new one
  • Remove the old table

This other Stackoverflow answer explains the process in details

like image 137
Alex Jasmin Avatar answered Oct 13 '22 08:10

Alex Jasmin