Opened 18 years ago
Closed 13 years ago
#5014 closed Bug (fixed)
manage.py inspect db is not using the new DecimalField
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | inspectdb |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi,
I've use the manage.py inspectdb utility. It's very nice but it is still using the model.FloatField rather than model.DecimalField.
Thanks
james
Attachments (3)
Change History (14)
comment:1 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 18 years ago
| Has patch: | set |
|---|
I've verified the problem on OSX, sqlite3, Py25. And i've verified that the problem is *not* present using MySQL 5ish, debian, Py24.
From the code, i'm guessing this is a problem with the sqlite introspection only. The Postgres and Oracle code both seem to already take DecimalFields into account (though i haven't tested this). I've attached a patch.
comment:3 by , 18 years ago
Can you reupload the patch ? it got lost by trac it seems (known issue over the weekend).
by , 18 years ago
| Attachment: | inspect_decimal_field.diff added |
|---|
comment:4 by , 18 years ago
| Summary: | manage.py inspect db is not using the new decimalField → manage.py inspect db is not using the new DecimalField |
|---|
comment:5 by , 15 years ago
| Needs tests: | set |
|---|
comment:6 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Bug |
comment:7 by , 15 years ago
| Easy pickings: | unset |
|---|---|
| Needs tests: | unset |
| Patch needs improvement: | set |
I added a patch which adds guessed max_digits and decimal_places for SQLite (with a notice) because decimal fields in SQLite are simply mapped as real (float) type. This way, the output of inspectdb is valid.
The problem with the current patch is that it doesn't pass with MySQL. Strangely, my version of mysqldb (1.2.2-10+b1) is always returning the value + 2 in cursor.description[4] (precision). Is this a known mysqldb bug?
comment:8 by , 15 years ago
| Patch needs improvement: | unset |
|---|
After some more research, I think that this might be due to historically reasons. MySQL used to store decimal fields as strings, and the length returned was also counting a place for the dot and the sign, hence the + 2.
I'm attaching a patch that fixes this peculiarity in MySQL introspection file.
comment:9 by , 14 years ago
| Component: | Database layer (models, ORM) → Core (Management commands) |
|---|---|
| Keywords: | inspectdb added |
| UI/UX: | unset |
comment:11 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
This model:
class DecimalTest(models.Model): test = models.DecimalField(max_digits=10, decimal_places=3)will be introspected as:
class TimesheetDecimaltest(models.Model): id = models.IntegerField(primary_key=True) test = models.TextField() # This field type is a guess. class Meta: db_table = u'timesheet_decimaltest'using activepython 2.5.1 under windows xp, with sqlite3 backend.
Could you please add more details about your config, especially the backend you used?