{"record":{"id":"bf71b8a2cb36f773","repo":"hashicorp/terraform","slug":"error-copying-state-from-the-previous-1-q-2-s","errorCode":null,"errorMessage":"Error copying state from the previous %[1]q %[2]s to the newly configured\n%[3]q %[4]s:\n    %[5]s\n\nThe state in the previous %[2]s remains intact and unmodified. Please resolve\nthe error above and try again.\n","messagePattern":"Error copying state from the previous %\\[1\\]q %\\[2\\]s to the newly configured\n%\\[3\\]q %\\[4\\]s:\n    %\\[5\\]s\n\nThe state in the previous %\\[2\\]s remains intact and unmodified\\. Please resolve\nthe error above and try again\\.\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":470,"sourceCode":"\n\t\t// Confirm with the user whether we want to copy state over\n\t\tconfirm, err := confirmFunc(sourceState, destinationState, opts)\n\t\tif err != nil {\n\t\t\tlog.Print(\"[TRACE] backendMigrateState: error reading input, so aborting migration\")\n\t\t\treturn err\n\t\t}\n\t\tif !confirm {\n\t\t\tlog.Print(\"[TRACE] backendMigrateState: user cancelled at confirmation prompt, so aborting migration\")\n\t\t\treturn nil\n\t\t}\n\t}\n\n\t// Confirmed! We'll have the statemgr package handle the migration, which\n\t// includes preserving any lineage/serial information where possible, if\n\t// both managers support such metadata.\n\tlog.Print(\"[TRACE] backendMigrateState: migration confirmed, so migrating\")\n\tif err := statemgr.Migrate(destinationState, sourceState); err != nil {\n\t\treturn fmt.Errorf(strings.TrimSpace(errBackendStateCopy),\n\t\t\topts.SourceType, srcWord,\n\t\t\topts.DestinationType, dstWord, err)\n\t}\n\t// The backend is currently handled before providers are installed during init,\n\t// so requiring schemas here could lead to a catch-22 where it requires some manual\n\t// intervention to proceed far enough for provider installation. To avoid this,\n\t// when migrating to HCP Terraform backend, the initial JSON varient of state won't be generated and stored.\n\tif err := destinationState.PersistState(nil); err != nil {\n\t\treturn fmt.Errorf(strings.TrimSpace(errBackendStateCopy),\n\t\t\topts.SourceType, srcWord,\n\t\t\topts.DestinationType, dstWord, err)\n\t}\n\n\t// And we're done.\n\treturn nil\n}\n\nfunc (m *Meta) backendMigrateEmptyConfirm(source, destination statemgr.Full, opts *backendMigrateOpts) (bool, error) {","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_migrate.go#L452-L488","documentation":"Returned by the single-to-single migration when `statemgr.Migrate(destinationState, sourceState)` fails after user confirmation and lock acquisition. The source state is preserved intact; the user is told to resolve the error and retry. Migrate preserves lineage/serial where possible.","triggerScenarios":"Fires in `backendMigrateState_s_s` after confirmation when the actual state-copy primitive errors — schema/version incompatibility between source and destination state, out-of-memory on a very large state, or an internal statemgr assertion.","commonSituations":"Migrating across Terraform major versions whose state schemas differ, an extremely large state file, lineage/serial conflicts between two non-empty states, or a state file written by an incompatible fork.","solutions":["Align source and destination Terraform/OpenTofu versions before migrating.","Inspect the embedded `%[5]s` error for the statemgr-specific failure (schema, lineage, size).","If lineage conflicts, manually reconcile or pick one authoritative state and force.","Retry `terraform init -migrate-state=true` after resolving the schema/lineage issue."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Align Terraform/OpenTofu versions between source and destination first.\n# Example: pin the binary used for migration to match the source state version.\nterraform version  # confirm matches the version that wrote the source state\nterraform init -input=false -migrate-state=true","typeGuard":null,"tryCatchPattern":"# Schema/lineage copy failures are not transient — report and stop:\nif ! terraform init -input=false -migrate-state=true >/tmp/init.log 2>&1; then\n  grep -q 'Error copying state' /tmp/init.log \\\n    && { echo 'State copy failed; check schema/lineage compatibility' >&2; exit 2; }\n  cat /tmp/init.log; exit 1\nfi","preventionTips":["Migrate within the same major Terraform/OpenTofu version.","Inspect state lineage/serial when both states are non-empty before migrating.","Back up both states before any cross-version migration."],"tags":["backend","migration","single-state","state-copy","schema","lineage","init"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}