Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions django_sharding_library/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from django.db.backends.postgresql.base import DatabaseWrapper as PostgresDatabaseWrapper
except ImportError:
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper as PostgresDatabaseWrapper
except ImportError:
PostgresDatabaseWrapper = None

try:
from django.db.models import BigAutoField
Expand Down Expand Up @@ -172,6 +174,8 @@ class ShardForeignKeyStorageField(ShardForeignKeyStorageFieldMixin, ForeignKey):
class BasePostgresShardGeneratedIDField(object):

def __init__(self, *args, **kwargs):
if not PostgresDatabaseWrapper:
raise ImportError("Psycopg2 2.5 or higher is required")

if not hasattr(settings, 'SHARD_EPOCH'):
raise ValueError("PostgresShardGeneratedIDField requires a SHARD_EPOCH to be defined in your settings file.")
Expand Down