django-jython icon indicating copy to clipboard operation
django-jython copied to clipboard

django.db.utils.Error: ERROR: there is no parameter $1 [SQLCode: 0], [SQLState: 42P02]

Open woodz- opened this issue 8 years ago • 3 comments

Good evening, first I'd like to thank you for putting power into django on jython.

My setup is as follows:

  • Ubuntu 16.04.1 LTS (Xenial Xerus)
  • Jython 2.7.0
  • django-jython 1.8.0b3
  • PostgreSQL 9.5.5
  • postgresql-9.4.1212.jar

I try to make a tiny migration in my model, while having some data in the DB already. before:

class Prio(MO.Model):
  '''priority of a srs'''
  name = MO.CharField('name of a priority of a srs', max_length=30)

  def __unicode__(self):
    return unicode(self.name)


class Srs(MO.Model):
  '''software requirement specification'''
  txt = MO.TextField('description of the software requirement specification (srs)', max_length=2000)
  prio = MO.ForeignKey(Prio, on_delete=MO.CASCADE)

  def __unicode__(self):
    return unicode(self.txt)

  class Meta:
    verbose_name_plural = "requirements"

after:

class Prio(MO.Model):
  '''priority of a srs'''
  name = MO.CharField('name of a priority of a srs', max_length=30)

  def __unicode__(self):
    return unicode(self.name)


class Cat(MO.Model):
  '''category of a srs'''
  name = MO.CharField('name of a category of a srs', max_length=50)

  def __unicode__(self):
    return unicode(self.name)


class Srs(MO.Model):
  '''software requirement specification'''
  txt = MO.TextField('description of the software requirement specification (srs)', max_length=2000)
  prio = MO.ForeignKey(Prio, on_delete=MO.CASCADE)
  cat = MO.ForeignKey(Cat, on_delete=MO.CASCADE)

  def __unicode__(self):
    return unicode(self.txt)

  class Meta:
    verbose_name_plural = "requirements"

then I do:

$ jython manage.py makemigrations srs
You are trying to add a non-nullable field 'cat' to srs without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows)
 2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()
>>> 0
Migrations for 'srs':
  0004_auto_20170118_1708.py:
    - Create model Cat
    - Add field cat to srs

then:

$ jython manage.py sqlmigrate srs 0004
BEGIN;
CREATE TABLE "srs_cat" ("id" serial NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL);
ALTER TABLE "srs_srs" ADD COLUMN "cat_id" integer DEFAULT 0 NOT NULL;
ALTER TABLE "srs_srs" ALTER COLUMN "cat_id" DROP DEFAULT;
CREATE INDEX "srs_srs_05e7bb57" ON "srs_srs" ("cat_id");
ALTER TABLE "srs_srs" ADD CONSTRAINT "srs_srs_cat_id_6260789c_fk_srs_cat_id" FOREIGN KEY ("cat_id") REFERENCES "srs_cat" ("id") DEFERRABLE INITIALLY DEFERRED;
COMMIT;

then:

$ jython manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages, doj
  Apply all migrations: sessions, auth, admin, sites, srs, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying srs.0004_auto_20170118_1708...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/someuser/dev/venv/Lib/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/someuser/dev/venv/Lib/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/someuser/dev/venv/Lib/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/someuser/dev/venv/Lib/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/someuser/dev/venv/Lib/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/migrations/operations/fields.py", line 60, in database_forwards
    schema_editor.add_field(
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/backends/base/schema.py", line 398, in add_field
    self.execute(sql, params)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/backends/base/schema.py", line 111, in execute
    cursor.execute(sql, params)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/someuser/dev/venv/Lib/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/someuser/dev/venv/Lib/site-packages/doj/db/backends/__init__.py", line 185, in execute
    self.cursor.execute(sql, params)
django.db.utils.Error: ERROR: there is no parameter $1 [SQLCode: 0], [SQLState: 42P02]

the only way I found by now is to work around with: $ jython manage.py migrate --fake <app-name> zero which is pretty annoying since I have to:

  • back up my DB
  • delete all user (application) spcific data tables
  • make migrations again
  • migrate again
  • edit backed up DB table schema according to new model
  • reimport backed up user tables

Can you think of an idea from where it comes from? From the pgsql jar adapter?

Thanks in advance! Greetings woodz

woodz- avatar Jan 18 '17 21:01 woodz-

@woodz- the project is dead ?

yishenggudou avatar Nov 14 '17 03:11 yishenggudou

the fork was an accident, sorry.

On 14.11.2017 04:32, timger wrote:

@woodz- [1] the project is dead ?

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or mute the thread [3].

Links:

[1] https://github.com/woodz- [2] https://github.com/beachmachine/django-jython/issues/13#issuecomment-344135927 [3] https://github.com/notifications/unsubscribe-auth/AJ50d0CRd-aN5MjK1DkgbLDoTSha0k6tks5s2Qm_gaJpZM4LncZV

woodz- avatar Nov 14 '17 09:11 woodz-

@yishenggudou seems so, even on jython itself there is no official traffic

woodz- avatar Nov 14 '17 14:11 woodz-