-
Book Overview & Buying
-
Table Of Contents
Building RESTful Python Web Services
By :
When we created the Category model, we specified the True value for the unique argument when we created the db.Column instance named name. As a result, the migrations generated the necessary unique constraint to make sure that the name field has unique values in the category table. This way, the database won't allow us to insert duplicate values for category.name. However, the error message generated when we try to do so is not clear.
Run the following command to create a category with a duplicate name. There is already an existing category with the name equal to 'Information':
http POST :5000/api/categories/ name='Information'
The following is the equivalent curl command:
curl -iX POST -H "Content-Type: application/json" -d '{"name":"Information"}'
:5000/api/categories/
The previous command will compose and send a POST HTTP request with the specified JSON key-value pair. The unique constraint in the category.name field won't allow the database...