Files
Muhammad Qasim Gulzar 68a53b8506 fix: error on postgresql 14 due to BIGSERIAL (#38040)
This pull request makes a targeted update to how PostgreSQL database
types are specified in the courseware/fields.py file. Specifically,
it changes the type returned for PostgreSQL from BIGSERIAL to BIGINT
in both the db_type and rel_db_type methods. This ensures that
auto-incrementing behavior is not implicitly assumed and aligns with 
scenarios where a plain integer type is needed.
2026-03-07 20:12:57 -05:00

37 lines
1.4 KiB
Python

"""
Custom fields
"""
from django.db.models.fields import AutoField
class UnsignedBigIntAutoField(AutoField):
"""
An unsigned 8-byte integer for auto-incrementing primary keys.
"""
def db_type(self, connection):
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':
return "bigint UNSIGNED AUTO_INCREMENT"
elif connection.settings_dict['ENGINE'] == 'django.db.backends.sqlite3':
# Sqlite will only auto-increment the ROWID column. Any INTEGER PRIMARY KEY column
# is an alias for that (https://www.sqlite.org/autoinc.html). An unsigned integer
# isn't an alias for ROWID, so we have to give up on the unsigned part.
return "integer"
elif "postgresql" in connection.settings_dict['ENGINE']:
# Pg's bigserial is implicitly unsigned (doesn't allow negative numbers) and
# goes 1-9.2x10^18
return "BIGINT"
else:
return None
def rel_db_type(self, connection):
if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':
return "bigint UNSIGNED"
elif connection.settings_dict['ENGINE'] == 'django.db.backends.sqlite3':
return "integer"
elif "postgresql" in connection.settings_dict['ENGINE']:
return "BIGINT"
else:
return None