The following code in a fresh project/app will cause the database
creation to fail.

class Position(models.Model):
    description = models.CharField(max_length=20, blank=True,
null=True)
    parts = models.ManyToManyField('Part', db_table='part_positions')

class PartPosition(models.Model):
    rule_id = models.IntegerField(primary_key=True, editable=False)
    part = models.ForeignKey('Part')
    position = models.ForeignKey('Position')

    class Meta:
        db_table = 'part_positions'

class Part(models.Model):
    description = models.CharField(max_length=20, blank=True,
null=True)
    positions = models.ManyToManyField('Position',
db_table='part_positions')


python ./manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table testapp1_position
Creating table part_positions
Creating table testapp1_part
Traceback (most recent call last):
  File "./manage.py", line 11, in ?
    execute_manager(settings)
  File "/usr/lib/python2.4/site-packages/django/core/management/
__init__.py", line 350, in execute_manager
    utility.execute()
  File "/usr/lib/python2.4/site-packages/django/core/management/
__init__.py", line 295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.4/site-packages/django/core/management/
base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.4/site-packages/django/core/management/
base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.4/site-packages/django/core/management/
base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/usr/lib/python2.4/site-packages/django/core/management/
commands/syncdb.py", line 92, in handle_noargs
    cursor.execute(statement)
  File "/usr/lib/python2.4/site-packages/django/db/backends/util.py",
line 19, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/django/db/backends/sqlite3/
base.py", line 190, in execute
    return Database.Cursor.execute(self, query, params)
pysqlite2.dbapi2.OperationalError: table "part_positions" already
exists

The django project I am working with is mapped to an existing
database, so this only causes a problem when tests are run, since the
test system creates its temporary database.

On Apr 2, 7:42 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
> On Thu, Apr 2, 2009 at 9:23 PM, Andrew G. <agross...@gmail.com> wrote:
>
> > I have a django app that is built against an existing database.  In
> > the database, there are a couple tables used as the many-to-many
> > relation lookup table.  However, I have mapped models to the many-to-
> > many lookup table, since I have a need for accessing these entries
> > directly.  Since the tables already exists, manage.py syncdb has no
> > problems, but when running manage.py test, the attempt to create the
> > test database complains that the many-to-many table already exists and
> > fails out.
>
> > Is there a way to specify ignoring the creation of this table
> > somewhere, or another way to circumvent this problem?  Should this be
> > considered a bug?
>
> I'm not sure I understand your situation here. When you run manage.py
> test, Django creates an entirely new, clean database. There shouldn't
> be any pre-existing tables. Can you elaborate on exactly what you are
> doing to generate this error?
>
> Yours,
> Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to