summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorHelen ST <helenst@gmail.com>2013-09-23 15:00:46 +0100
committerTim Graham <timograham@gmail.com>2013-09-23 11:51:58 -0400
commit41167645b1039067127fa215d4d28296bfa4cfdc (patch)
treef031af72fab8f12416e4a226ab8ef14685b708b0 /django
parenta53caf28bf2ab29cf4e78a968b3887ddb6d6e83d (diff)
Fixed #14028 - Added validation for clashing db_columns.
Thanks akaariai for the suggestion.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/validation.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/django/core/management/validation.py b/django/core/management/validation.py
index 1c23871481..85897ee9e2 100644
--- a/django/core/management/validation.py
+++ b/django/core/management/validation.py
@@ -63,6 +63,9 @@ def get_validation_errors(outfile, app=None):
if not opts.get_field(cls.USERNAME_FIELD).unique:
e.add(opts, 'The USERNAME_FIELD must be unique. Add unique=True to the field parameters.')
+ # Store a list of column names which have already been used by other fields.
+ used_column_names = []
+
# Model isn't swapped; do field-specific validation.
for f in opts.local_fields:
if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
@@ -75,6 +78,17 @@ def get_validation_errors(outfile, app=None):
# consider NULL and '' to be equal (and thus set up
# character-based fields a little differently).
e.add(opts, '"%s": Primary key fields cannot have null=True.' % f.name)
+
+ # Column name validation.
+ # Determine which column name this field wants to use.
+ _, column_name = f.get_attname_column()
+
+ # Ensure the column name is not already in use.
+ if column_name and column_name in used_column_names:
+ e.add(opts, "Field '%s' has column name '%s' that is already used." % (f.name, column_name))
+ else:
+ used_column_names.append(column_name)
+
if isinstance(f, models.CharField):
try:
max_length = int(f.max_length)