postgres : column "id" violates not-null constraint\n Detail: Failing row contains - postgresql

Hi i'm new with java web develpment
i wrote a simple play framework app with java
i want to save some contact in a ebean database it works well in my pc
i deployed my app in heroku and i'm using postgres plugin
the problem is when i POST the following request i get that error
req:/contacts/post?name=name&email=email%40mail.com&phone=234234
err:
play.api.UnexpectedException: Unexpected exception[PersistenceException: ERROR executing DML bindLog[] error[ERROR: null value in column "id" violates not-null constraint\n Detail: Failing row contains (null, name, 234234, email#mail.com).]]
but if i add &id=223434 it works well!!

Related

Import a single pdf file to Dspace 6.X on Centos 7

I try to import a new single pdf file to Dspace 6.3 in Centos 7 after successful backup files from batch import (ZIP), but in xmlui page get several errors:
When i try import, error after accept license: Error while attempting to create identifier for Item id: 0b85c570-ab76-483a-9cdc-3db7b26716cb
When i try create new community: ERROR: duplicate key value violates unique constraint "handle_handle_key" Detail: Key (handle)=(123456789/41) already exists.
When i try create new collection: ERROR: duplicate key value violates unique constraint "handle_handle_key" Detail: Key (handle)=(123456789/42) already exists.
How i can fix these problems? Before backup i easily imported new pdf files, but after backup i get these problems

insert null value for auto incremented primary key

I'm using aws glue and i'm trying to insert (in pg databases) line with null value in primary key. I get this error :
An error occurred while calling o204.pyWriteDynamicFrame. ERROR: null value in column "abc" violates not-null constraint.
The issue is that primary key has a sequence
nextval('abc'::regclass).
Is it a parameter in glue to avoid this error ? Thanks
Conf :
AWS GLUE,
Python job,
Postgres databases

Ecto.Repo.insert! with "on_conflict: :nothing" raising a Postgresql "syntax error at or near "ON""

I'm totally new to Elixir and Phoenix, and am currently working through the book "Programming Phoenix."
I've reached chapter 7 and I have a database table called categories with a column name and a DB-level uniqueness constraint on name.
If I run the following line when a category called "Hello" already exists, I get an Ecto.ConstraintError as expected:
> Rumbl.Repo.insert!(%Rumbl.Multimedia.Category{name: "Hello"})
[debug] QUERY ERROR db=3.2ms queue=4.9ms idle=9982.9ms
INSERT INTO "categories" ("name","inserted_at","updated_at") VALUES ($1,$2,$3) RETURNING "id" ["Hello", ~N[2020-04-18 07:05:04], ~N[2020-04-18 07:05:04]]
** (Ecto.ConstraintError) constraint error when attempting to insert struct:
* categories_name_index (unique_constraint)
Now, the book tells me that I can add the option on_conflict: :nothing to my call to insert! and it will prevent an error from being raised. But what actually happens is I get a postgres syntax error:
> Rumbl.Repo.insert!(%Rumbl.Multimedia.Category{name: "Hello"}, on_conflict: :nothing)
** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near "ON"
query: INSERT INTO "categories" ("name","inserted_at","updated_at") VALUES ($1,$2,$3) ON CONFLICT DO NOTHING RETURNING "id"
(ecto_sql) lib/ecto/adapters/sql.ex:612: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto) lib/ecto/repo/schema.ex:657: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:263: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:164: Ecto.Repo.Schema.insert!/4
[debug] QUERY ERROR db=0.0ms queue=0.8ms idle=9038.9ms
INSERT INTO "categories" ("name","inserted_at","updated_at") VALUES ($1,$2,$3) ON CONFLICT DO NOTHING RETURNING "id" ["Hello", ~N[2020-04-18 07:05:13], ~N[2020-04-18 07:05:13]]
Version numbers:
Elixir 1.9.4
Phoenix 1.4.10
Ecto 3.4.2
Postgres 12.1
Turns out I was mistaken that my postgres version is 12.1, this is actually the installed version of my psql client and not my postgres server, which was running 9.4. ON CONFLICT was added in 9.5, so the solution is to upgrade my postgres server.

Spring Boot 2 - H2 Database - #SpringBootTest - Failing on org.h2.jdbc.JdbcSQLException: Table already exists

Unable to test Spring Boot & H2 with a script for creation of table using schema.sql.
So, what’s happening is that I have the following properties set:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:city;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
and, I expect the tables to be created using the schema.sql. The application works fine when I run gradle bootRun. However, when I run tests using gradle test, my tests for Repository passes, but the one for my Service fails stating that it’s trying to create the table when the table already exists:
Exception raised:
Caused by: org.h2.jdbc.JdbcSQLException: Table "CITY" already exists;
SQL statement:
CREATE TABLE city ( id BIGINT NOT NULL, country VARCHAR(255) NOT NULL, map VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, state VARCHAR(2555) NOT NULL, PRIMARY KEY (id) ) [42101-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:117)
at org.h2.command.CommandContainer.update(CommandContainer.java:101)
at org.h2.command.Command.executeUpdate(Command.java:260)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:192)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:164)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:471)
... 105 more
The code is setup and ready to recreate the scenario. README has all the information ->
https://github.com/tekpartner/learn-spring-boot-data-jpa-h2
If the tests are run individually, they pass. I think the problem is due to schema.sql being executed twice against the same database. It fails the second time as the tables already exist.
As a workaround, you could set spring.datasource.continue-on-error=true in application.properties.
Another option is to add the #AutoConfigureTestDatabase annotation where appropriate so that a unique embedded database is used for each test.
There are 2 other possible solutions you could try:
Add a drop table if exists [tablename] in your schema.sql before you create the table.
Change the statement from CREATE TABLE to CREATE TABLE IF NOT EXISTS

Is there any way to skip migrations which are failing?

I want to run migration on my server for ruby on rails project but I am getting this kind of error with postgres-
PGError: ERROR: relation "last_message_read" already exists
: CREATE TABLE "last_message_read" ("id" serial primary key, "message" character varying(255), "company_id" integer)
So, I want to continue with my migration but it is not happening - I want to ignore those migration which are failing and continue with the rest....
Something's wrong with your migrations. Just reset your db (rake db:reset).