通过Python API创建Bigquery表

时间:2022-11-30 15:31:05

I'm trying to create a Bigquery table using Python API.

我正在尝试使用Python API创建Bigquery表。

from google.cloud import bigquery

bigquery_client = bigquery.Client(project="myproject")
dataset = bigquery_client.dataset("mydataset")

table = dataset.table("mytable")
table.create()

I keep getting this error

我一直收到这个错误

AttributeError: 'TableReference' object has no attribute 'create'

AttributeError:'TableReference'对象没有属性'create'

Does anyone have any idea?

有人有什么主意吗?

1 个解决方案

#1


3  

You're getting back a TableReference object, not a Table on your 2nd last line (table = dataset.table("mytable")). You need to do this:

你得到的是一个TableReference对象,而不是你最后一行的Table(table = dataset.table(“mytable”))。你需要这样做:

[..]
table_ref = dataset.table('my_table')
table = bigquery.Table(table_ref, schema=SCHEMA)
table = client.create_table(table)
[..]

See here.

#1


3  

You're getting back a TableReference object, not a Table on your 2nd last line (table = dataset.table("mytable")). You need to do this:

你得到的是一个TableReference对象,而不是你最后一行的Table(table = dataset.table(“mytable”))。你需要这样做:

[..]
table_ref = dataset.table('my_table')
table = bigquery.Table(table_ref, schema=SCHEMA)
table = client.create_table(table)
[..]

See here.