summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/crud.py12
-rw-r--r--lib/sqlalchemy/sql/schema.py2
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py
index 881ea9fcd..58abc10df 100644
--- a/lib/sqlalchemy/sql/crud.py
+++ b/lib/sqlalchemy/sql/crud.py
@@ -534,13 +534,21 @@ def _append_param_insert_pk(compiler, stmt, c, values, kw):
no value passed in either; raise an exception.
"""
+
if (
# column has a Python-side default
c.default is not None
and (
- # and it won't be a Sequence
+ # and it either is not a sequence, or it is and we support
+ # sequences and want to invoke it
not c.default.is_sequence
- or compiler.dialect.supports_sequences
+ or (
+ compiler.dialect.supports_sequences
+ and (
+ not c.default.optional
+ or not compiler.dialect.sequences_optional
+ )
+ )
)
) or (
# column is the "autoincrement column"
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 8c325538c..c7d699a5f 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -2281,6 +2281,8 @@ class Sequence(roles.StatementRole, DefaultGenerator):
.. seealso::
+ :ref:`defaults_sequences`
+
:class:`.CreateSequence`
:class:`.DropSequence`