Ticket #1972: management.diff

File management.diff, 818 bytes (added by James Bennett, 18 years ago)

Patch which makes syncdb raise ImproperlyConfigured on a model with no fields

  • management.py

     
    456456    for app in models.get_apps():
    457457        model_list = models.get_models(app)
    458458        for model in model_list:
     459            # If the model has no fields, throw an error.
     460            if len(model._meta.fields) == 1 and model._meta.fields[0].get_internal_type() == 'AutoField':
     461                raise ImproperlyConfigured, "model '%s' in application '%s' has no fields; models must have at least one explicit non-primary-key field" % (model._meta.object_name, model._meta.app_label)
    459462            # Create the model's database table, if it doesn't already exist.
    460463            if model._meta.db_table in table_list:
    461464                continue
Back to Top