Hi,
I am trying to create a custom table in Umbraco using the following code. However, it fails to create the table. There are no logs even.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// create database tables
CreateTables(applicationContext);
}
public static void CreateTables(ApplicationContext applicationContext)
{
//Get the Umbraco Database context
var dbContext = applicationContext.DatabaseContext;
//Get the Database Helper
var helper = new DatabaseSchemaHelper(dbContext.Database, applicationContext.ProfilingLogger.Logger, dbContext.SqlSyntax);
//Check if the DB table does NOT exist
if (!helper.TableExist("Comment"))
{
//Create DB table - and set overwrite to false
helper.CreateTable<Comment>(false);
}
}
Create custom tables in Umbraco
Hi, I am trying to create a custom table in Umbraco using the following code. However, it fails to create the table. There are no logs even.
Thanks /Bilal
Hi Bilal,
can you show us your Comment DTO class?
Make sure you have added the namespace:
And added the attribute:
to your Comment class.
/Michaël
Here you go:
Can you add a breakpoint in your
CreateTables
to see what happens during every step?/Michaël
For some reason, VS is getting stuck on the line of
And suddenly it opens the page without letting me continue debugging. Any idea why?
Thanks
Can you show me the full code of your events class?
I was looking at the wrong database. I was using Compact Edition. The table was actually created!
However, now when I try to add a new record I receive this message:
Is there a way to set the IDENTITY_INSERT to ON using the DTO class?
Thanks
You have a issue in your DTO class.
You have added the attribute:
But then on your property you add the attribute:
And your property is called:
Change it to
id
orcommentId
, don't mix them up.Hope this helps!
/Michaël
Hi Michael, Can you pls have a look at a related post here: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/80071-using-constraint-with-custom-data-table-cannot-insert-nulls
Thanks
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.