{"record":{"id":"d4cac8b89e40cb0d","repo":"v2rayA/v2rayA","slug":"failed-to-get-last-insert-id-for-subscription-d","errorCode":null,"errorMessage":"failed to get last insert id for subscription %d: %w","messagePattern":"failed to get last insert id for subscription (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/db/migrate.go","lineNumber":311,"sourceCode":"\n\tfor i, r := range results {\n\t\taddress := r.Get(\"address\").String()\n\t\tremarks := r.Get(\"remarks\").String()\n\t\tstatus := r.Get(\"status\").String()\n\t\tinfo := r.Get(\"info\").String()\n\t\tautoSelect := 0\n\t\tif r.Get(\"autoSelect\").Bool() {\n\t\t\tautoSelect = 1\n\t\t}\n\n\t\tres, err := subStmt.Exec(address, remarks, status, info, autoSelect, i)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to insert subscription %d: %w\", i, err)\n\t\t}\n\n\t\tsubID, err := res.LastInsertId()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get last insert id for subscription %d: %w\", i, err)\n\t\t}\n\n\t\t// Record the mapping: BoltDB index (0-based) -> SQLite subscription ID\n\t\tsubIDMap[int64(i)] = subID\n\n\t\t// Migrate servers within this subscription\n\t\tservers := r.Get(\"servers\").Array()\n\t\tfor j, s := range servers {\n\t\t\tconfigJSON := s.Raw\n\t\t\tif _, err := serverStmt.Exec(subID, configJSON, j); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to insert subscription server %d/%d: %w\", i, j, err)\n\t\t\t}\n\t\t}\n\n\t\tlog.Info(\"Migrated subscription %d with %d servers\", i, len(servers))\n\t}\n\n\treturn subIDMap, nil","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/service/db/migrate.go#L293-L329","documentation":"Raised in migrateSubscriptions when res.LastInsertId fails after a successful subscription insert — the row was written but its new SQLite rowid cannot be retrieved (driver or database error), so the BoltDB-index→SQLite-id mapping needed to migrate the subscription's servers cannot be built.","triggerScenarios":"Thrown at service/db/migrate.go:311 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry migration from a clean SQLite file","Check SQLite driver/database health"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}