Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#453 closed enhancement (fixed)

Descriptive error messages in django-admin sql/install

Reported by: GrumpySimon Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be very helpful, especially for newer users, to have descriptive error messages when installing/generating SQL for the models.

Example - if you don't specify maxlength=x on a CharField, the resulting error is:

Error: projectname couldn't be installed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables already exists.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlall projectname'. That's the SQL this command wasn't able to run.
The full error: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'None) NOT NULL,\n ")

The problem is that this tries to create a field of type "varchar ( None )" (Note: This error is on MySQL 4.1.17 - I'm not sure how Postgres/SQLite will handle it, but I'd guess that a "None" will fail there too).

A quick look at the code shows that you could do this error checking inside the get_sql_create() function in management.py around line 73 - eg:

if datatype == 'CharField' and rel_field.maxlength == None:
   print 'Error! "%s" must have a max_length value set' % ( f.column )

However, it's probably not a good idea to pollute management.py with error checking, especially if you want to go the whole route and do complete error checking of all inputs ( eg: check valid parameters for each field type in the database API ).

It would be even better if you could distinguish between the error returns:

  • The database isn't running or isn't configured correctly.
  • At least one of the database tables already exists.
  • The SQL was invalid.

Surely the error code that's returned by the database handler gives enough information to distinguish?

(Currently running SVN 600)

Change History (1)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [609].

Note: See TracTickets for help on using tickets.
Back to Top