BigQuery: The sample to create a BigQuery table is not working #8703
Closed
Description
-
Specify the API at the beginning of the title (for example, "BigQuery: ...")
General, Core, and Other are also allowed as types
This sample to be exact: https://github.com/googleapis/google-cloud-python/blob/7ba0220ff9d0d68241baa863b3152c34dc9f7a1a/bigquery/samples/create_table.py -
OS type and version
MacOS Mojave -
Python version and virtual environment information:
python --version
Both 2.7.10 and 3.7 -
google-cloud- version:
pip show google-<service>
orpip freeze
google-cloud-bigquery==1.9.0
Steps to reproduce
- set GOOGLE_APPLICATION_CREDENTIALS to my service account key
- Make sure "gcloud config list" items are correct.
- In the sample code, set table_id to: "{}.datalabeling.cont_eval".format(PROJECT_ID)
- Run the sample.
Code example
def create_big_query_table():
schema = [
bigquery.SchemaField("model", "STRING", mode="REQUIRED"),
bigquery.SchemaField("model_version", "INTEGER", mode="REQUIRED"),
]
client = bigquery.Client()
PROJECT_ID = 'my-gcp-project-id'
table_id = "{}.datalabeling.cont_eval".format(PROJECT_ID)
table = bigquery.Table(table_id, schema=schema)
table = client.create_table(table) # API request
print(table)
Stack trace
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shahins/.virtualenvs/dl2/lib/python2.7/site-packages/google/cloud/bigquery/table.py", line 370, in __init__
self._properties = {"tableReference": table_ref.to_api_repr(), "labels": {}}
AttributeError: 'str' object has no attribute 'to_api_repr'
(the line that throws this exception is bigquery.Table(.....))
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!