Unable to create a partitioned table on s3 data

Constantine
Contributor III

I write data to s3 like

data.write.format("delta").mode("append").option("mergeSchema", "true").save(s3_location)

and create a partitioned table like

CREATE TABLE IF NOT EXISTS demo_table
USING DELTA
PARTITIONED BY (column_a)
LOCATION {s3_location};

which throws an error

Error in SQL statement: AnalysisException: It is not allowed to specify partitioning when the table schema is not defined.

Is there a different way to write to s3 location so that I can solve this issue