You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/06_sql_storage_sqlalchemy/05_insert_models_sqlalchemy/README.md
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,13 @@ description: Learn how to use SQLAlchemy to add new rows to our SQL database.
14
14
Inserting models with SQLAlchemy couldn't be easier! We'll use the `db.session`[^1] variable to `.add()` a model. Let's begin working on our `Item` resource:
15
15
16
16
```python title="resources/item.py"
17
+
from sqlalchemy.exc import SQLAlchemyError
18
+
19
+
from db import db
20
+
from models import ItemModel
21
+
22
+
...
23
+
17
24
@blp.arguments(ItemSchema)
18
25
@blp.response(201, ItemSchema)
19
26
defpost(self, item_data):
@@ -31,6 +38,13 @@ def post(self, item_data):
31
38
Similarly in our `Store` resource:
32
39
33
40
```python title="resources/store.py"
41
+
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
0 commit comments