Ends in:
2 DAYS
2 HRS
40 MIN
27 SEC
Ends in:
2 D
2 H
40 M
27 S
Open Closed

SQLite Error 19: 'FOREIGN KEY constraint failed' when running tests in 7.3.2 #5551


User avatar
0
Sturla created

After updating (from 7.2.2) I´m getting the error below when running my tests. I´m getting this for all my tests. After having searched I found this 2 year old issue and that led me to unchecking the required tick for the navigation property and the tests started working!

Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module LF.SearchPortal.SearchPortalTestBaseModule, LF.SearchPortal.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: An error occurred while saving the entity changes. See the inner exception for details.. See the inner exception for details. ---- Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while saving the entity changes. See the inner exception for details. -------- Microsoft.Data.Sqlite.SqliteException : SQLite Error 19: 'FOREIGN KEY constraint failed'.

    Stack Trace: 
ModuleManager.InitializeModules(ApplicationInitializationContext context)
AbpApplicationBase.InitializeModules()
AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider)
AbpIntegratedTest`1.ctor()
SearchPortalTestBase`1.ctor()
SearchPortalDomainTestBase.ctor()
SampleDomainTests.ctor() line 18
RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
----- Inner Stack Trace -----
ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
<30 more frames...>
ModuleManager.InitializeModules(ApplicationInitializationContext context)
----- Inner Stack Trace -----
SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
SqliteDataReader.NextResult()
SqliteCommand.ExecuteReader(CommandBehavior behavior)
SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)

Btw I expect to get this question refunded since this feature is not working and has caused me half a day of nothing...

  • ABP Framework version: v7.3.2
  • UI Type: Blazor Server
  • Database System: EF Core PostgreSQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

6 Answer(s)
  • User Avatar
    0
    Sturla created

    There is btw another error in regarding "required" and that is that if you mark a property as required the tests will also fail!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    What are the steps to get this error from a new 7.2.2 template project?

  • User Avatar
    0
    Sturla created

    I tried to replicate the issue from a new 7.3.2 project but that didn´t work (there is no error) so it must be related to something being missed from the migration (I only used the update button)

    Steps:

    1. Create a 7.2.2 project
      1. Application template
      2. Blazor Server
      3. Lepton-X
      4. Maui
      5. PostgreSQL
      6. Separate tenant schema
      7. Add entities (see below)
      8. Run update with update button in Suite

    ScrapingContent.json

    {
      "Id": "4ad61650-48d0-4212-80e1-a18b8762397a",
      "Name": "ScrapingContent",
      "OriginalName": "ScrapingContent",
      "NamePlural": "ScrapingContents",
      "DatabaseTableName": "ScrapingContents",
      "Namespace": "ScrapingContents",
      "BaseClass": "AuditedEntity",
      "MenuIcon": "file-alt",
      "PrimaryKeyType": "Guid",
      "IsMultiTenant": false,
      "CheckConcurrency": true,
      "ShouldCreateUserInterface": true,
      "ShouldCreateBackend": true,
      "ShouldExportExcel": true,
      "ShouldAddMigration": true,
      "ShouldUpdateDatabase": false,
      "CreateTests": true,
      "Properties": [
        {
          "Id": "d8fdc266-5d2f-4a81-8da5-e361cf427a8f",
          "Name": "Html",
          "Type": "string",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": null,
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": false,
          "MinLength": null,
          "MaxLength": null,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": false,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        },
        {
          "Id": "ffda4627-bf56-4e0d-8bb4-37ece256656d",
          "Name": "DateScraped",
          "Type": "DateTime",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": null,
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": false,
          "MinLength": null,
          "MaxLength": null,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": true,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        }
      ],
      "NavigationProperties": [
        {
          "EntityNameWithDuplicationNumber": "ScrapingUrl",
          "EntitySetNameWithDuplicationNumber": "ScrapingUrls",
          "ReferencePropertyName": "ScrapingUrl",
          "UiPickType": "Dropdown",
          "IsRequired": true,
          "Name": "ScrapingUrlId",
          "DisplayProperty": "Name",
          "Namespace": "TestNotWorking.ScrapingUrls",
          "EntityName": "ScrapingUrl",
          "EntitySetName": "ScrapingUrls",
          "DtoNamespace": "TestNotWorking.ScrapingUrls",
          "DtoEntityName": "ScrapingUrlDto",
          "Type": "Guid"
        }
      ],
      "NavigationConnections": [],
      "PhysicalFileName": "ScrapingContent.json"
    }
    

    ScrapingUrl.json

    {
      "Id": "7b77295e-508a-4b0e-9d7e-e7caf2088cce",
      "Name": "ScrapingUrl",
      "OriginalName": "ScrapingUrl",
      "NamePlural": "ScrapingUrls",
      "DatabaseTableName": "ScrapingUrls",
      "Namespace": "ScrapingUrls",
      "BaseClass": "AuditedEntity",
      "MenuIcon": "file-alt",
      "PrimaryKeyType": "Guid",
      "IsMultiTenant": false,
      "CheckConcurrency": true,
      "ShouldCreateUserInterface": true,
      "ShouldCreateBackend": true,
      "ShouldExportExcel": false,
      "ShouldAddMigration": true,
      "ShouldUpdateDatabase": false,
      "CreateTests": true,
      "Properties": [
        {
          "Id": "b459187f-9946-4c43-b804-21f6637b16b4",
          "Name": "Name",
          "Type": "string",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": null,
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": false,
          "MinLength": null,
          "MaxLength": 52,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": false,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        },
        {
          "Id": "0f10d82b-e7b3-4b64-aba6-af46b2df5f03",
          "Name": "Url",
          "Type": "string",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": null,
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": false,
          "MinLength": null,
          "MaxLength": 1024,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": false,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        },
        {
          "Id": "d1752e3a-2d18-45a2-91ac-5b1d0f5505f5",
          "Name": "IsActive",
          "Type": "bool",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": "true",
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": false,
          "MinLength": null,
          "MaxLength": null,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": false,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        },
        {
          "Id": "38718158-9a68-4251-acda-898e4e4eb3ca",
          "Name": "LastError",
          "Type": "string",
          "EnumType": "",
          "EnumNamespace": "",
          "EnumAngularImport": "shared/enums",
          "EnumFilePath": null,
          "DefaultValue": null,
          "IsNullable": false,
          "IsRequired": false,
          "IsTextArea": true,
          "MinLength": null,
          "MaxLength": 1024,
          "SortOrder": 0,
          "SortType": 0,
          "Regex": "",
          "EmailValidation": false,
          "ShowOnList": true,
          "ShowOnCreateModal": true,
          "ShowOnEditModal": true,
          "ReadonlyOnEditModal": false,
          "EnumValues": null,
          "IsSelected": true,
          "OrdinalIndex": 0
        }
      ],
      "NavigationProperties": [],
      "NavigationConnections": [],
      "PhysicalFileName": "ScrapingUrl.json"
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Add entities (see below)

    I can't add entities by JSON. Do you have another way to reproduce the exception?

    SQLite Error 19: 'FOREIGN KEY constraint failed'.

    It looks like there is a constraint problem with the data, you can check it first.

  • User Avatar
    0
    Sturla created

    I haven´t had time to look at this again so don´t close this!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    sure.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35