2017-03-13 21 views
8

bir öğe alırken hata "sağlanan anahtar unsur şema eşleşmiyor" Bu bir öğe almaya çalıştım enter image description hereDynamoDB

tablo içeriği enter image description here

ayar tablosu bölüm anahtarıdır tablodan, bu Bu benim kodudur

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema

bu hatayı yazdırır

dynamodb = boto3.resource('dynamodb') 
table = dynamodb.Table('testDynamodb') 
response = table.get_item(Key={'userId': "user2873"}) 
item = response['Item'] 
print(item) 

Herhangi bir fikrin var mı? Teşekkürler.

cevap

8

Tablo şemanızın hem karma anahtarı hem de bölüm anahtarı tanımlanmış. işleri

response = table.get_item(Key={'userId': "user2873", 'createdAt': "1489376547"}) 
0

Bir başka şey: DynamoDB GetItem kullanırken ikisini de sağlaması gerekir, işte böyle görünmeli Get_Item parametreler olduğunu Yani örnek verilen documentation

For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.

bir alıntıdır aşağıdaki kod aşağıdadır:

result = table.query(
     KeyConditionExpression=Key('userId').eq('user2873') 
    ) 
İlgili konular