Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#1368 closed defect (fixed)

Command 'python init' doesn't work with MySQL 5.0.17/18 under Windows

Reported by: quarkcool@… Owned by: adrian
Component: Database layer (models, ORM) Version: magic-removal
Severity: major Keywords: init mysql error #1005
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Hi everyone, I think I've found a bug.

The problem

Today I checked out the magic-removal branch and tried to use it. I started a project (with startproject), I changed to add the correct database settings, and then I tried to initialize the database (with python init). The following error was displayed :

Error: models 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 ' sqlall models'. That's the SQL this command wasn't able to run.
The full error: (1005, "Can't create table '.\\django\\#sql-780_6b.frm' (errno: 150)")
Error: The database couldn't be initialized.
Traceback (most recent call last):

  File "C:\Program Files\Python\lib\site-packages\django\core\", line 494, in init

  File "C:\Program Files\Python\lib\site-packages\django\core\", line 548, in install

SystemExit: 1

After a little search on my own, I found that the following SQL query :

ALTER TABLE `auth_message` ADD CONSTRAINT `user_id_referencing_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);

was the source of the problem. Indeed, MySQL complained because the user_id field wasn't exactly the same type as the id field in table auth_user.

The temporary solution

I managed to install the auth app by manually entering the output of python sqlall auth and adding the following query before the one that caused the problem :

ALTER TABLE `auth_message` CHANGE `user_id` `user_id` MEDIUMINT( 9 ) UNSIGNED NOT NULL 

The type of user_id and the type of were now equivalent, and the query succeeded without problem.

So that's it, I don't think that using Windows is the problem here, maybe I'll try on Linux with the appropriate version of MySQL.

If this can be reproduced, that's a big problem because it means you can't initialize a project with the latest MySQL 5.0.

Thanks for your time

Change History (3)

comment:1 Changed 10 years ago by sj@…

I can confirm this with MySQL 4.1.12 under Linux. The auto-generated primary key should be an INT(11), just as the foreign key field. Right now primary keys are generated as MEDIUMINT(9).

comment:2 Changed 10 years ago by Andy Dustman <farcepest@…>

Ticket #1500 has a patch for this issue.

comment:3 Changed 9 years ago by adrian

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

Fixed in [2582].

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