【问题标题】:flask Dynamo CreateTable operation Issue (botocore.exceptions.ClientError)flask Dynamo CreateTable 操作问题(botocore.exceptions.ClientError)
【发布时间】:2017-09-08 14:17:21
【问题描述】:

尝试使用flask-dynamo在Dynamo db中创建包含三个字段的表,得到错误“”

botocore.exceptions.ClientError botocore.exceptions.ClientError:调用CreateTable操作时发生错误(ValidationException):键模式中的属性数必须与属性定义中定义的属性数匹配

这里是配置创建表发电机数据库

@app.route('/create_table')
def create_table():
    app.config['DYNAMO_TABLES'] = [
    {
        'TableName': "user_detail",
        'KeySchema': [
            {'AttributeName': "timestamp", 'KeyType': "HASH"},
            {'AttributeName': "question", 'KeyType': "RANGE"},
        ],
        'AttributeDefinitions': [
            {'AttributeName': "timestamp", 'AttributeType': "S"},
            {'AttributeName': "question", 'AttributeType': "N"},
            {'AttributeName': "user", 'AttributeType': "N"},
        ],
        'ProvisionedThroughput': {
            'ReadCapacityUnits': 40,
            'WriteCapacityUnits': 40
        }
    }]
     dynamo = Dynamo(app)
     with app.app_context():
          dynamo.create_all()
     return "Table created"

提前致谢

【问题讨论】:

    标签: python-3.x amazon-web-services flask amazon-dynamodb


    【解决方案1】:

    您需要删除以下行:

    {'AttributeName': "user", 'AttributeType': "N"},
    

    使用 DynamoDB(与大多数 NoSQL 数据库一样),您无需提前指定每个记录属性字段。您只需要提前指定哈希和范围字段。

    【讨论】:

    • 我是 dynamo db 的初学者,我如何定义两个以上的属性
    • 您永远不会将那些其他属性定义为表模式的一部分。您只需插入具有您想要的任何属性的记录(除了 hash 和 key 属性)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2020-01-19
    • 2018-12-09
    • 1970-01-01
    • 2018-05-09
    • 2019-07-14
    • 2021-05-02
    相关资源
    最近更新 更多