Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On 2月4日, 下午12时03分, Malcolm Tredinnick 
wrote:
> On Tue, 2009-02-03 at 19:47 -0800, Eric Abrahamsen wrote:
>
> > On Feb 4, 11:25 am, Malcolm Tredinnick 
> > wrote:
> > > On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > > > Hi there,
>
> > > > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > > > Entry" error when loading. From what I've googled, this might have
> > > > something to do with a mismatch between my model definitions and the
> > > > sql table definition.
>
> > > "Duplicate Entry" is the database telling you that some column(s) with a
> > > unique constraint are failing the constraint check. So it's
> > > database-level data related and the first thing to check is the data
> > > you're trying to insert.
>
> > Aha! I had assumed duplicate entry meant it thought there were two
> > rows with the same pk. On second thought, that wouldn't make too much
> > sense.
>
> It could very well mean that. A primary key column has a uniqueness
> constraint as part of the requirement (it has to be unique and not-NULL,
> pretty much by definition). In fact, since the only column with a unique
> constraint in the table you give is the primary key column, it almost
> has to be that one that is the problem.

I guess the problem wasn't duplicate pks, but egregious quantities of
otherwise-illegal data, mostly NULL values where empty strings were
required. Even after correcting the bad data (and doing a reset and
reloading it with loaddata, which went without a hitch) I still got
the error whenever I dumped the entire database and loaded it in
testcases as a single fixture. But dumping apps separately, and
loading them only as needed for individual testcases, has cleared
things up. It's left me a little suspicious of my whole setup (can I
get a test framework for my test framework?), but at least it's
working.

Thanks for pushing me in the right direction.

E


>
> > This only helps a little bit, though, since none of the fields have
> > unique=True, none of the db columns are unique, and I've got no
> > unique_together constraints. The fixture is a direct output of
> > dumpdata, in xml format (I get the same error with JSON). The pks are
> > included, but there's no duplication there.
>
> The database would like to disagree with you and I'm inclined to trust
> it.
>
> So either (a) there is a duplicate primary key value, (b) the database
> table is not empty to start with and one of the existing entries clash,
> or (c) you are trying to load that fixture more than once without
> flushing the previous data.
>
> The problem is definitely in the data and/or the number of times it's
> being loaded. So trim things down. For example, what happens if you cut
> it in half? If you reduce it to only a single line? Just the second half
> instead of the first half? What happens if you try to load the data
> manually using "loaddata" into an empty database, instead of using the
> test framework? Et cetera, et cetera.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 19:47 -0800, Eric Abrahamsen wrote:
> 
> 
> On Feb 4, 11:25 am, Malcolm Tredinnick 
> wrote:
> > On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > > Hi there,
> >
> > > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > > Entry" error when loading. From what I've googled, this might have
> > > something to do with a mismatch between my model definitions and the
> > > sql table definition.
> >
> > "Duplicate Entry" is the database telling you that some column(s) with a
> > unique constraint are failing the constraint check. So it's
> > database-level data related and the first thing to check is the data
> > you're trying to insert.
> 
> Aha! I had assumed duplicate entry meant it thought there were two
> rows with the same pk. On second thought, that wouldn't make too much
> sense.

It could very well mean that. A primary key column has a uniqueness
constraint as part of the requirement (it has to be unique and not-NULL,
pretty much by definition). In fact, since the only column with a unique
constraint in the table you give is the primary key column, it almost
has to be that one that is the problem.

> This only helps a little bit, though, since none of the fields have
> unique=True, none of the db columns are unique, and I've got no
> unique_together constraints. The fixture is a direct output of
> dumpdata, in xml format (I get the same error with JSON). The pks are
> included, but there's no duplication there.

The database would like to disagree with you and I'm inclined to trust
it.

So either (a) there is a duplicate primary key value, (b) the database
table is not empty to start with and one of the existing entries clash,
or (c) you are trying to load that fixture more than once without
flushing the previous data.

The problem is definitely in the data and/or the number of times it's
being loaded. So trim things down. For example, what happens if you cut
it in half? If you reduce it to only a single line? Just the second half
instead of the first half? What happens if you try to load the data
manually using "loaddata" into an empty database, instead of using the
test framework? Et cetera, et cetera.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On Feb 4, 11:25 am, Malcolm Tredinnick 
wrote:
> On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > Hi there,
>
> > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > Entry" error when loading. From what I've googled, this might have
> > something to do with a mismatch between my model definitions and the
> > sql table definition.
>
> "Duplicate Entry" is the database telling you that some column(s) with a
> unique constraint are failing the constraint check. So it's
> database-level data related and the first thing to check is the data
> you're trying to insert.

Aha! I had assumed duplicate entry meant it thought there were two
rows with the same pk. On second thought, that wouldn't make too much
sense.

This only helps a little bit, though, since none of the fields have
unique=True, none of the db columns are unique, and I've got no
unique_together constraints. The fixture is a direct output of
dumpdata, in xml format (I get the same error with JSON). The pks are
included, but there's no duplication there.

This is the full model definition: http://dpaste.com/116418/
and the full output of describe table: http://dpaste.com/116419/

If you've got a moment and can see anything in there that's obviously
wrong, I'd appreciate any pointers. Otherwise, I've got a better sense
of how to go about hunting this down now.

Thanks a lot,
Eric



> [...]
>
> > The only unusual thing about the second record is that it's the first
> > one with "characters" set to an empty string. I'm using a django
> > updated earlier in the day.
>
> If the primary key specified in the data you're trying to insert? If so,
> and it's not different between the two, that's one case of a unique
> field that will be causing you problems.
>
> If you know which two records are causing the problem, another part of
> reducing the problem to the simplest case is to try a few experiements.
> Each time, change one of the pieces of data in the second entry. At some
> point, you'll change the attribute that is causing the problem, so
> you'll at least know which one it is.
>
>
>
> > model
> > 
>
> > class Author(models.Model):
> >   surname = models.CharField(max_length=30)
> >   given_name = models.CharField(max_length=30)
> >   slug = models.SlugField(blank=True)
> >   characters = models.CharField(max_length=6,blank=True)
> >   user = models.ForeignKey(User, blank=True, null=True)
> > ...more
>
> Yeah, that "more" bit is no doubt containing important information. For
> example, do you have a Meta inner class that is defining any
> unique_together constraints? Do any of the fields you've omitted have
> unique=True on them? Which columns in the database table require the
> entries to be unique?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Malcolm Tredinnick

On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> Hi there,
> 
> I'm unable to do any testing -- my fixtures fail with a "Duplicate
> Entry" error when loading. From what I've googled, this might have
> something to do with a mismatch between my model definitions and the
> sql table definition. 

"Duplicate Entry" is the database telling you that some column(s) with a
unique constraint are failing the constraint check. So it's
database-level data related and the first thing to check is the data
you're trying to insert.
[...]

> The only unusual thing about the second record is that it's the first
> one with "characters" set to an empty string. I'm using a django
> updated earlier in the day.

If the primary key specified in the data you're trying to insert? If so,
and it's not different between the two, that's one case of a unique
field that will be causing you problems.

If you know which two records are causing the problem, another part of
reducing the problem to the simplest case is to try a few experiements.
Each time, change one of the pieces of data in the second entry. At some
point, you'll change the attribute that is causing the problem, so
you'll at least know which one it is.


> 
> model
> 
> 
> class Author(models.Model):
>   surname = models.CharField(max_length=30)
>   given_name = models.CharField(max_length=30)
>   slug = models.SlugField(blank=True)
>   characters = models.CharField(max_length=6,blank=True)
>   user = models.ForeignKey(User, blank=True, null=True)
> ...more

Yeah, that "more" bit is no doubt containing important information. For
example, do you have a Meta inner class that is defining any
unique_together constraints? Do any of the fields you've omitted have
unique=True on them? Which columns in the database table require the
entries to be unique?

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



getting database definition in line

2009-02-03 Thread Eric Abrahamsen

Hi there,

I'm unable to do any testing -- my fixtures fail with a "Duplicate
Entry" error when loading. From what I've googled, this might have
something to do with a mismatch between my model definitions and the
sql table definition. This fails on a model that I've done a lot of
manual sql editing on, so it's likely that I've inadvertently screwed
something up. After messing with this for an afternoon, I'm just going
to post the first few lines of the model and the output of DESCRIBE
TABLE, and I hope someone will see something obviously wrong here. The
fixture loading fails like this:
IntegrityError: (1062, "Duplicate entry 'dbase-author' for key 2")

The only unusual thing about the second record is that it's the first
one with "characters" set to an empty string. I'm using a django
updated earlier in the day.

model


class Author(models.Model):
  surname = models.CharField(max_length=30)
  given_name = models.CharField(max_length=30)
  slug = models.SlugField(blank=True)
  characters = models.CharField(max_length=6,blank=True)
  user = models.ForeignKey(User, blank=True, null=True)
...more

DESCRIBE TABLE
#
Field Type Null Key Default Extra
id int(11) no pri null auto_increment
surname varchar(30) no [blank] [blank] [blank]
given_name varchar(30) no [blank] [blank] [blank]
slug varchar(50) no [blank] [blank] [blank]
characters varchar(6) no [blank] [blank] [blank]
user_id int(11) yes mul null [blank]
...more


Is this something to do with having a foreignkey that's set to
blank=True,null=True?

TIA,
Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---