SQLite alter columns, delete columns restrictions

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
[email protected]
Posts: 4
Joined: Mon 18 Jan 2016 09:24

SQLite alter columns, delete columns restrictions

Post by [email protected] » Mon 27 Jun 2016 06:34

SQLite has a very limited support to alter tables. The recommended workaround is to create a new table with the altered columns and the copy the data from the old table to the newly created.

Question: is there any generic implementation available (c# using EF/Devart classes) so that no explicit SQL-statements must be written?
i.e. something like this:

Code: Select all

void AlterTable(string existingTableName, Type newTableEntity)
This method could use the both argument to create the statement.


By issuing the add-migration command Visual Studio generated the migration script. This file contains code that created the requested tables:

Code: Select all

CreateTable(
	"dbo.Permission",
	c => new
		{
			Id = c.NotNullableVarchar(32),
			Name = c.String(nullable: false),
			IsDeleted = c.Boolean(nullable: false),
		})
	.PrimaryKey(t => t.Id);
I suspect there are some helper methods in EF available to obtain metainfo of the columns for a table that is used by the add-migration tool to generate the script. In a similar way the above mentioned AlterTable command could use the metainfo of a table to generate the column list for the CreateTablemethod. Further also the primary keys, indices, ... could be created by analizing the metadata.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: SQLite alter columns, delete columns restrictions

Post by Shalex » Fri 01 Jul 2016 12:49

[email protected] wrote:SQLite has a very limited support to alter tables.
That is correct.
SQLite itself supports a limited subset of ALTER TABLE (http://www.sqlite.org/lang_altertable.html). The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. That's why EF Migration Operation Support for SQLite is limited: http://blog.devart.com/entity-framework ... ionSupport.
[email protected] wrote:The recommended workaround is to create a new table with the altered columns and the copy the data from the old table to the newly created.
Question: is there any generic implementation available (c# using EF/Devart classes) so that no explicit SQL-statements must be written?
Please submit your suggestion at https://devart.uservoice.com/forums/105 ... rk-support.

Post Reply