migration-scripts icon indicating copy to clipboard operation
migration-scripts copied to clipboard

SQLITE_CONSTRAINT: NOT NULL constraint failed

Open dawnerd opened this issue 3 years ago • 1 comments

Running Mongo -> Sql

[Error: insert into `haunts` (`Name`, `Slug`, `created_at`, `id`, `updated_at`) values ('SeaWorld San Diego’s Howl-O-Scream', 'sea-world-san-diego-s-howl-o-scream', '2021-03-14 22:04:41.060', 1, '2021-03-14 22:06:44.220') - SQLITE_CONSTRAINT: NOT NULL constraint failed: haunts.CurrentlyOperating] {
  errno: 19,
  code: 'SQLITE_CONSTRAINT'
}

Schema for that:

{
  "kind": "collectionType",
  "collectionName": "haunts",
  "info": {
    "name": "Haunts",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "Name": {
      "type": "string",
      "required": true
    },
    "Slug": {
      "type": "uid",
      "targetField": "Name",
      "required": true
    },
    "AlternativeNames": {
      "type": "component",
      "repeatable": true,
      "component": "common.alternative-names"
    },
    "CurrentlyOperating": {
      "type": "boolean",
      "default": true,
      "required": true
    },
    "Geo": {
      "type": "json"
    },
    "IsTempClosed": {
      "type": "boolean",
      "default": false,
      "required": true
    },
    "Park": {
      "model": "parks"
    },
    "NiceName": {
      "type": "string"
    },
    "MainPhoto": {
      "model": "file",
      "via": "related",
      "allowedTypes": [
        "images"
      ],
      "plugin": "upload",
      "required": false
    },
    "CoverPhoto": {
      "model": "file",
      "via": "related",
      "allowedTypes": [
        "images"
      ],
      "plugin": "upload",
      "required": false
    },
    "Gallery": {
      "collection": "file",
      "via": "related",
      "allowedTypes": [
        "images"
      ],
      "plugin": "upload",
      "required": false
    },
    "Sections": {
      "type": "dynamiczone",
      "components": [
        "text.section-header",
        "text.text"
      ]
    },
    "Region": {
      "model": "regions",
      "via": "Haunts"
    },
    "OpeningDate": {
      "type": "string"
    },
    "ClosedDate": {
      "type": "string"
    },
    "HauntYears": {
      "via": "Haunt",
      "collection": "haunt-years"
    },
    "Attribute": {
      "type": "component",
      "repeatable": true,
      "component": "attraction.attribute"
    }
  }
}

dawnerd avatar Jun 04 '22 15:06 dawnerd

So luckily the data that was failing was experimental and I was able to just remove it and continue on.

I did run into another issue:

Error: Empty .update() call detected! Update data does not contain any values to update. This will result in a faulty query. Table: ride_credits. Columns: Attraction.
    at QueryCompiler_SQLite3._prepUpdate (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/query/querycompiler.js:1213:13)
    at QueryCompiler_SQLite3.update (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/query/querycompiler.js:193:29)
    at QueryCompiler_SQLite3.toSQL (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/query/querycompiler.js:73:29)
    at Builder.toSQL (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/query/querybuilder.js:83:44)
    at ensureConnectionCallback (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:4:30)
    at Runner.ensureConnection (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/execution/runner.js:272:20)
    at async Runner.run (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/node_modules/knex/lib/execution/runner.js:30:19)
    at async run (/home/troy/Projects/migration-scripts/v3-mongodb-v3-sql/index.js:275:15)

I just wrapped that bit of code in a try just to get it to complete. Seems there's some old data somewhere that is missing a connection, nbd really.

Apart from this the script seems to have been successful at migrating ~4k documents with complex relations. Good job ya'll! 🎉

dawnerd avatar Jun 04 '22 15:06 dawnerd