{"record":{"id":"c40fa10244629c64","repo":"apache/iceberg","slug":"cannot-create-table-s-as-the-namespace-does-not-e-c40fa1","errorCode":null,"errorMessage":"Cannot create table %s as the namespace does not exist","messagePattern":"Cannot create table (.+?) as the namespace does not exist","errorType":"exception","errorClass":"org.apache.iceberg.exceptions.NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/BaseTableCreationSparkAction.java","lineNumber":164,"sourceCode":"        \"Cannot create Iceberg table in non-Iceberg Catalog. \"\n            + \"Catalog '%s' was of class '%s' but '%s' or '%s' are required\",\n        catalog.name(),\n        catalog.getClass().getName(),\n        SparkSessionCatalog.class.getName(),\n        SparkCatalog.class.getName());\n\n    return (StagingTableCatalog) catalog;\n  }\n\n  protected StagedSparkTable stageDestTable() {\n    try {\n      Map<String, String> props = destTableProps();\n      StructType schema = sourceTable.schema();\n      Transform[] partitioning = sourceTable.partitioning();\n      return (StagedSparkTable)\n          destCatalog().stageCreate(destTableIdent(), schema, partitioning, props);\n    } catch (org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException e) {\n      throw new NoSuchNamespaceException(\n          \"Cannot create table %s as the namespace does not exist\", destTableIdent());\n    } catch (org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException e) {\n      throw new AlreadyExistsException(\n          \"Cannot create table %s as it already exists\", destTableIdent());\n    }\n  }\n\n  protected void ensureNameMappingPresent(Table table) {\n    if (!table.properties().containsKey(TableProperties.DEFAULT_NAME_MAPPING)) {\n      NameMapping nameMapping = MappingUtil.create(table.schema());\n      String nameMappingJson = NameMappingParser.toJson(nameMapping);\n      table.updateProperties().set(TableProperties.DEFAULT_NAME_MAPPING, nameMappingJson).commit();\n    }\n  }\n\n  protected String getMetadataLocation(Table table) {\n    String defaultValue =\n        LocationUtil.stripTrailingSlash(table.location()) + \"/\" + ICEBERG_METADATA_FOLDER;","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/BaseTableCreationSparkAction.java#L146-L182","documentation":"When staging the destination table for migrate/snapshot actions, destCatalog().stageCreate throws Spark's NoSuchNamespaceException if the destination namespace does not exist. The action converts it into Iceberg's NoSuchNamespaceException with this message. The destination database must exist before staging the new table.","triggerScenarios":"Running MIGRATE or SNAPSHOT with a destination identifier whose namespace (database) does not exist in the destination catalog, e.g. CALL system.migrate('db.new_table') where db is missing.","commonSituations":"Typo in the destination database name; running against a new catalog where the namespace was never created; case sensitivity mismatch in namespace names.","solutions":["Create the destination namespace first: CREATE NAMESPACE <catalog>.<ns>","Check the destination identifier for typos in the namespace part","Verify you are pointing at the intended catalog (spark.sql.catalog.<name>)"],"exampleFix":"// before\nCALL iceberg.system.migrate('prod_db.new_iceberg_tbl') -- prod_db missing in iceberg catalog\n// after\nCREATE NAMESPACE iceberg.prod_db;\nCALL iceberg.system.migrate('prod_db.new_iceberg_tbl');","handlingStrategy":"validation","validationCode":"// Ensure destination namespace exists before migrating\nSHOW NAMESPACES IN iceberg; // or\nCREATE NAMESPACE IF NOT EXISTS iceberg.prod_db;","typeGuard":null,"tryCatchPattern":"try { ... } catch (NoSuchNamespaceException e) { spark.sql(\"CREATE NAMESPACE \" + ns); retry(); }","preventionTips":["Always CREATE NAMESPACE the destination before running migrate/snapshot","Double-check namespace spelling and case in the destination catalog","Confirm spark.sql.catalog.<name> points at the catalog you intend"],"tags":["spark","namespace","catalog","table-creation"],"backgroundTag":"entity-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}