4
votes

I tried to append data from a query to a bigquery table.

Job ID job_i9DOuqwZw4ZR2d509kOMaEUVm1Y

Error: Job failed while writing to Bigquery. invalid: Illegal Schema update. Cannot add fields (field: debug_data) at null

I copy and paste the query executed in above jon, run it in web console and choose the same dest table to append, it works.

2

2 Answers

7
votes

The job you listed is trying to append query results to a table. That query has a field named 'debug_data'. The table you're appending to does not have that field. This behavior is by design, in order to prevent people from accidentally modifying the schema of their tables.

You can run a tables.update() or tables.patch() operation to modify the table schema to add this column (see an example using bq here: Bigquery add columns to table schema), and then you'll be able to run this query successfully.

Alternately, you could use truncate instead of append as the write disposition in your query job; this would overwrite the table, and in doing so, will allow schema changes.

0
votes

See this post for how to have bigquery automatically add new fields to a schema while doing an append.

The code in python is:

job_config.schema_update_options = ['ALLOW_FIELD_ADDITION']