Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
How to alter/modify existing table in StartUp.cs?Please let me know in detail.
first of all welcome to the Umbraco community!
Could you explain more in detail what you are trying to do? Which existing table do you which to modify and why?
I wants to modify custom table which I have created.For e.g I wants to add more columns and wants to change datatype of existing columns.
thank you for posting back with more details.
For your question, follow the link that @Dave has posted here in this thread about Migrations in Umbraco.
This will allow you to apply changes to existing tables using code.
Hope this helps.
You can use migrations. See this blog for more information :
What table are you trying to modify ? Is it a custom table or Umbraco table.
If it's a Umbraco table I would urge you not to do this.
any news on this issue? Can you share it with the community.
Thanks for your feedback!
Create a "custom table". Don't touch Umbraco tables.
If you need create table at startup create a similar class in your project:
public class XUmbracoStartup : ApplicationEventHandler
protected override void ApplicationStarted(UmbracoApplicationBase umbraco, ApplicationContext context)
LogHelper.Info(this.GetType(), "XM ApplicationStarted");
var ctx = context.DatabaseContext;
DatabaseSchemaHelper db = new DatabaseSchemaHelper(ctx.Database, context.ProfilingLogger.Logger, ctx.SqlSyntax);
// Create DB table - and set overwrite to false
protected virtual void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
LogHelper.Info(this.GetType(), "XM ApplicationStarting");
I don't think this is the best way to create custom tables. It's better to use migrations. This is how umbraco handles it.
Because they only run once. Your code will run on every time the application starts.
Also changing tables like, eg adding a column, become a pain in the ass. Using this code. Not even talking about indexes, constraints etc..
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted