Exception when creating an API User

Stock Umbraco 18.0.2

Trying to create an API User produces:

www_zpqrtbnk  | Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'userType', table 'ZpqrtBnk.WebSite.dbo.umbracoUser'; column does not allow nulls. INSERT fails.
www_zpqrtbnk  | The statement has been terminated.
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
www_zpqrtbnk  |    at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar()
www_zpqrtbnk  |    at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
www_zpqrtbnk  |    at NPoco.Database.ExecuteScalarHelper(DbCommand cmd)
www_zpqrtbnk  |    at NPoco.Database.InsertAsyncImp[T](PocoData pocoData, String tableName, String primaryKeyName, Boolean autoIncrement, T poco, Boolean sync, CancellationToken cancellationToken)
www_zpqrtbnk  |    at NPoco.Database.InsertAsyncImp[T](PocoData pocoData, String tableName, String primaryKeyName, Boolean autoIncrement, T poco, Boolean sync, CancellationToken cancellationToken)
www_zpqrtbnk  |    at NPoco.Database.Insert[T](String tableName, String primaryKeyName, Boolean autoIncrement, T poco)
www_zpqrtbnk  |    at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.UserRepository.PersistNewItem(IUser entity)
www_zpqrtbnk  |    at Umbraco.Cms.Core.Cache.DefaultRepositoryCachePolicy`2.Create(TEntity entity, Action`1 persistNew)
www_zpqrtbnk  |    at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.EntityRepositoryBase`2.Save(TEntity entity)
www_zpqrtbnk  |    at Umbraco.Cms.Core.Security.BackOfficeUserStore.SaveAsync(IUser user)
www_zpqrtbnk  |    at Umbraco.Cms.Core.Security.BackOfficeUserStore.CreateAsync(BackOfficeIdentityUser user, CancellationToken cancellationToken)
www_zpqrtbnk  |    at Microsoft.AspNetCore.Identity.UserManager`1.CreateCoreAsync(TUser user)
www_zpqrtbnk  |    at Microsoft.AspNetCore.Identity.UserManager`1.CreateAsync(TUser user)
www_zpqrtbnk  |    at Umbraco.Cms.Web.Common.Security.BackOfficeUserManager.CreateAsync(UserCreateModel createModel)
www_zpqrtbnk  |    at Umbraco.Cms.Core.Services.UserService.CreateAsync(Guid performingUserKey, UserCreateModel model, Boolean approveUser)

Rings a bell?

Is this an upgraded Umbraco instance? Maybe something went wrong with the migrations.

And what packages are you using, or maybe custom migrations that could interfere with things? Anything else in the log except this error?

Let’s also see what the umbracoUser table looks like. Execute this query on the database:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'umbracoUser'

Hi Stephan,

I don’t have any issue on an a blank V18 install.

I guess something went wrong with your upgrade.

I see the column “userType” used to exist in Umbraco, but it got renamed to “kind” in V15 as far as I can see.

But I actually don’t know if it ever shipped with V15 actually,

Is this a upgraded site ?

Dave

This would be the table:

TABLE_NAME    COLUMN_NAME              ORDINAL_POSITION COLUMN_DEFAULT  IS_NULLABLE DATA_TYPE         CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_PRECISION_RADIX NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_CATALOG  CHARACTER_SET_SCHEMA  CHARACTER_SET_NAME  COLLATION_CATALOG  COLLATION_SCHEMA  COLLATION_NAME   DOMAIN_CATALOG  DOMAIN_SCHEMA  DOMAIN_NAME 
------------- ------------------------ ---------------- --------------- ----------- ----------------- ------------------------ ---------------------- ----------------- ----------------------- ------------- ------------------ ---------------------- --------------------- ------------------- ------------------ ----------------- ---------------- --------------- -------------- ------------
umbracoUser   id                                      1 NULL            NO          int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   userDisabled                            2 ('0')           NO          bit                                   NULL                   NULL              NULL                    NULL          NULL               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   userNoConsole                           3 ('0')           NO          bit                                   NULL                   NULL              NULL                    NULL          NULL               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   userType                                4 NULL            NO          int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   startStructureID                        5 NULL            NO          int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   startMediaID                            6 NULL            YES         int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   userName                                7 NULL            NO          nvarchar                               255                    510              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   userLogin                               8 NULL            NO          nvarchar                               125                    250              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   userPassword                            9 NULL            NO          nvarchar                               500                   1000              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   userEmail                              10 NULL            NO          nvarchar                               255                    510              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   userLanguage                           11 NULL            YES         nvarchar                                10                     20              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   securityStampToken                     12 NULL            YES         nvarchar                               255                    510              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   failedLoginAttempts                    13 NULL            YES         int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   lastLockoutDate                        14 NULL            YES         datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   lastPasswordChangeDate                 15 NULL            YES         datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   lastLoginDate                          16 NULL            YES         datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   emailConfirmedDate                     17 NULL            YES         datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   invitedDate                            18 NULL            YES         datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   createDate                             19 (getutcdate())  NO          datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   updateDate                             20 (getutcdate())  NO          datetime                              NULL                   NULL              NULL                    NULL          NULL                  3 NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   avatar                                 21 NULL            YES         nvarchar                               255                    510              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   passwordConfig                         22 NULL            YES         nvarchar                               500                   1000              NULL                    NULL          NULL               NULL NULL                   NULL                  UNICODE             NULL               NULL              French_CI_AS     NULL            NULL           NULL        
umbracoUser   key                                    23 (newid())       NO          uniqueidentifier                      NULL                   NULL              NULL                    NULL          NULL               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        
umbracoUser   kind                                   24 ('0')           NO          int                                   NULL                   NULL                10                      10             0               NULL NULL                   NULL                  NULL                NULL               NULL              NULL             NULL            NULL           NULL        

As for “an upgrade instance”, well, that originally was a v4 site that has been upgraded up to 18.2, so yes :slight_smile: yet the table looks fine, userType is NOT NULL DEFAULT NULL so it must be provided. I have tried to create a normal user and it fails too.

No particular package installed, no custom migration. Not much more in the log than the exception above. Am going to try and run a debug build to see what query exactly is failing.

Hey Dave.

Indeed 18.2 source code has


[Column("kind")]
[NullSetting(NullSetting = NullSettings.NotNull)]
[Constraint(Default = 0)]
public short Kind { get; set; }

… and no userType column. Why is this in my DB? Now hunting for bogus migration…

Maybe a left over field from a long time ago that is not handled by a migration.

Dave

Hi Stephan,

I asked AI and got this answer

The userType column in the umbracoUser table existed in Umbraco versions prior to 7.7.0 (including Umbraco 4, 6, and 7.0 through 7.6.x).

In Umbraco 7.7.0, the backoffice user management system received a major overhaul to support role-based access control. As part of this database migration:

  • The userType column was permanently removed from the umbracoUser table.

  • The supporting umbracoUserType table was deleted.

  • The single user type system was replaced by User Groups. This allowed users to belong to multiple roles using the new umbracoUserGroup and umbracoUser2UserGroup (mapping) tables.

So this is probably a migration that did not execute correctly.

Dave

Yup, Claude confirms that this column should not exist in 18.2. So, first thing, drop the column, and the corresponding umbracoUserTypetable.

Now as for why … Claude hints at possible confusions during the 7.7 beta/RC period where it would have been possible to skip the deletion. Never mind. Fixed.

Or…

 Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'startStructureID', table 'ZpqrtBnk.WebSite.dbo.umbracoUser'; column does not allow nulls. INSERT fails.

Of course :slight_smile:

I would LOVE a healthcheck that would tell me hey, your DB does not look healthy.

OK, fixed, works, thanks for pointing me in the right direction!

And the reason is failed was that the column was not allowed to be null. And since nothing writes to it, it fails on that.

Glad I could help you !

And happy to see you are still using Umbraco.

Dave