Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#453 closed enhancement (fixed)

Descriptive error messages in django-admin sql/install

Reported by: GrumpySimon Owned by: adrian
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: UI/UX:

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)

Attachments (0)

Change History (1)

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [609].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.