ERROR: null value in column "id" violates not-null constraint - ruby

I just migrated my app from mysql to postgres but when I try to insert a record in a specific table I get violates not-null constraint error:
ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
********** Error **********
ERROR: null value in column "id" violates not-null constraint
SQL state: 23502
Detail: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
When I try to create the record using factory_girl:
#assignment = FactoryGirl.create(:assignment)
It builds this sql query:
INSERT INTO assignments(
id, account_id, l_id, viewed_at, accepted_at, declined_at,
expires_at, created_at, updated_at, decline_reason, decline_reason_text,
promotion, c_checked_at, forwardable, type, f_promo,
c_check_successful, c_check_api_result, c_check_human_result)
VALUES (null, 1, 1, null, null, null, '2016-03-09 09:24:12.841891', '2012-12-31 23:00:00', '2012-12-31 23:00:00', null, null, 'f', null, 'f', 'XYZAssignment', null, null, null, null);
This is the assignment factory:
FactoryGirl.define do
factory :assignment do
expires_at 24.hours.from_now
account
lead
end
end
this is the table description:
CREATE TABLE assignments(
id serial NOT NULL, account_id integer NOT NULL, l_id integer NOT NULL, viewed_at timestamp without time zone, accepted_at timestamp without time zone, declined_at timestamp without time zone, expires_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, decline_reason character varying(16), decline_reason_text character varying(256), promotion boolean NOT NULL DEFAULT false, c_checked_at timestamp without time zone, forwardable boolean DEFAULT true, type character varying(64), f_promo boolean, c_check_successful boolean, c_check_api_result character varying(32), c_check_human_result character varying(32), CONSTRAINT assignments_pkey PRIMARY KEY (id)
) WITH (
OIDS=FALSE
);
Looks its not able to auto increment the id, any idea?

You have to skip id in the INSERT operation:
INSERT INTO assignments(account_id, l_id, ...)
VALUES
(1, 1, ...)
The id will automatically get the next sequence number, since it is an auto-increment field.

Related

Unable to extract JDBC value for position `3`

I am switching from MYSQL to ORACLE.
I have JPA Authentication setup like this:
#Override
#Transactional(readOnly = true)
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
AppUser user = userRepository.findByUseremailIgnoreCase(email);
With MySQL all works fine. But for Oracle, during login using JPA authentication I am getting this exception.
org.springframework.security.authentication.InternalAuthenticationServiceException: Unable to extract JDBC value for position `3`
Followed by these exceptions:
Caused by: org.springframework.orm.jpa.JpaSystemException: Unable to extract JDBC value for position `3`
Caused by: java.sql.SQLException: Invalid conversion requested
Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
Any clue what I am missing and where to debug?
My table structure is as per below:
create table CONTENTPLUSPLUS.app_user (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
useremail VARCHAR(150) NOT NULL,
userpassword VARCHAR(150) NOT NULL,
useruuid VARCHAR(50) NOT NULL,
userfirstname VARCHAR(150) NOT NULL,
userlastname VARCHAR(150) NOT NULL,
userenabled NUMBER(1) DEFAULT 0 NOT NULL,
created_by VARCHAR(150) NOT NULL,
created_date VARCHAR(150) NOT NULL,
modified_by VARCHAR(150) NOT NULL,
modified_date VARCHAR(150) NOT NULL,
CONSTRAINT appuser_pk PRIMARY KEY (id), UNIQUE (useremail, useruuid));
create table CONTENTPLUSPLUS.app_role(
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
name VARCHAR(150) NOT NULL,
CONSTRAINT approle_pk PRIMARY KEY (id),UNIQUE (name));
CREATE TABLE CONTENTPLUSPLUS.app_department (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
departmentuuid VARCHAR(150),
departmentheadname varchar(255) NOT NULL,
departmentheademail varchar(255) NOT NULL,
departmentname varchar(255) NOT NULL,
userid NUMBER NOT NULL,
created_by VARCHAR(150) NOT NULL,
created_date VARCHAR(150) NOT NULL,
modified_by VARCHAR(150) NOT NULL,
modified_date VARCHAR(150) NOT NULL,
CONSTRAINT appdepartment_pk PRIMARY KEY (id),UNIQUE (departmentname, departmentuuid));
CREATE TABLE CONTENTPLUSPLUS.app_user_department (
userid NUMBER NOT NULL,
departmentid NUMBER NOT NULL
);
ALTER TABLE CONTENTPLUSPLUS.app_user_department ADD CONSTRAINT FK_AUSERDEPTUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
ALTER TABLE CONTENTPLUSPLUS.app_user_department ADD CONSTRAINT FK_AUSERDEPTDEPTID FOREIGN KEY (departmentid) REFERENCES app_department (id);
ALTER TABLE CONTENTPLUSPLUS.app_department ADD CONSTRAINT FK_AUSERUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
CREATE TABLE CONTENTPLUSPLUS.app_user_role (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
userid NUMBER NOT NULL,
roleid NUMBER NOT NULL,
CONSTRAINT appuserrole_pk PRIMARY KEY (id));
ALTER TABLE CONTENTPLUSPLUS.app_user_role ADD CONSTRAINT FK_AURUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
ALTER TABLE CONTENTPLUSPLUS.app_user_role ADD CONSTRAINT FK_AURROLEID FOREIGN KEY (roleid) REFERENCES app_role (id);
Below is the query which gets fired during the login operation (shows up only for MySQL):
Hibernate:
select
a1_0.id,
a1_0.created_by,
a1_0.created_date,
a1_0.modified_by,
a1_0.modified_date,
a1_0.useremail,
a1_0.userenabled,
a1_0.userfirstname,
a1_0.userlastname,
a1_0.userpassword,
a1_0.useruuid
from
app_user a1_0
where
upper(a1_0.useremail)=upper(?)
Hibernate:
select
r1_0.userid,
r1_1.id,
r1_1.name
from
app_user_role r1_0
join
app_role r1_1
on r1_1.id=r1_0.roleid
where
r1_0.userid=?
You map Date in Java with VARCHAR2 in SQL: bad idea. You probably get lucky with the default conversion format of TS and the locale in MySQL: back to my first comment... look at the SQL Office Hours session code...

i want to make a query to give condition to my board table

INSERT INTO ABOARD(BNO, BNAME, BPW, BTITLE, BCONTENT, BDATE, BGROUP,
BSTEP, BINDENT, COMCNT, ISDEL, HAVEFILE)
VALUES(#{bno}, #{bname }, #{bpw },
#{btitle }, #{bcontent }, SYSDATE, GROUPSEQ.NEXTVAL, 0, 0, 0,'N','N')
This is my board table.
I want to change the last column "HAVEFILE" if I add file to insert the board when I register.
below table is the attachment file. How to join two table or make a query?
CREATE TABLE MP_FILE
(
FILE_NO NUMBER,
BNO NUMBER NOT NULL,
ORG_FILE_NAME VARCHAR2(260) NOT NULL,
STORED_FILE_NAME VARCHAR2(36) NOT NULL,
FILE_SIZE NUMBER,
REGDATE DATE DEFAULT SYSDATE NOT NULL,
DEL_GB VARCHAR2(1) DEFAULT 'N' NOT NULL,
PRIMARY KEY(FILE_NO)
);

ORA-00906 missing left parenthesis error while creating table

Getting ORA-00906 error while creating table.
CREATE TABLE TEST.BSTXTEST(
PDBC_PFX CHAR NOT NULL,
BSBS_TYPE CHAR NOT NULL,
BSTX_SEQ_NO NUMBER NOT NULL,
BSTX_TEXT RAW NOT NULL,
BSTX_LOCK_TOKEN NUMBER NOT NULL,
ATXR_SOURCE_ID TIMESTAMP NOT NULL,
BSTXTEXT VARCHAR2(500) NOT NULL,
LENTEXT NUMBER NOT NULL
)
For a RAW datatype the size portion of the definition is mandatory.
e.g.
BSTX_TEXT RAW(2000) NOT NULL,

SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"

i have been trying to make a simple table and i it keeps coming up with SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"
CREATE TABLE USER_TABLE(
USER_ID int NOT NULL,
Username varchar NULL,
Password varchar NULL,
Email varchar NOT NULL,
DOB Date NULL,
Address VARCHAR NOT NULL,
First_name VARCHAR NOT NULL,
Telephone_number int NULL,
PRIMARY KEY (User_ID));
You simply need to add the size of VARCHAR colums:
CREATE TABLE USER_TABLE
(
USER_ID INT NOT NULL,
Username VARCHAR(1) NULL,
Password VARCHAR(1) NULL,
Email VARCHAR(1) NOT NULL,
DOB DATE NULL,
Address VARCHAR(1) NOT NULL,
First_name VARCHAR(1) NOT NULL,
Telephone_number INT NULL,
PRIMARY KEY(User_ID)
);
Notice that VARCHAR is deprecated, better use VARCHAR2

sqlite error near '''' syntax error data input

I am using sqlite3 and trying to put data into my database.
CREATE TABLE CLUB(
cl_id INT PRIMARY KEY NOT NULL,
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
dtm_opricht TEXT NOT NULL
);
CREATE TABLE STADION(
sta_id INT PRIMARY KEY NOT NULL,
cl_id INT REFERENCES CLUB(cl_id),
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
capaciteit INT NOT NULL,
dtm_bouw TEXT NOT NULL
);
CREATE TABLE TECHNISCHDIRECTEUR(
td_id INT PRIMARY KEY NOT NULL,
cl_id INT REFERENCES CLUB(cl_id),
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
salaris REAL NOT NULL,
nationaliteit TEXT NOT NULL,
geslacht TEXT NOT NULL,
dtm_geboorte TEXT NOT NULL
);
Everything was going fine with putting in data for the first 2 tables.
insert into CLUB values(101, 'Ajax', 'Amsterdamstraat 1', '05-01-1916');
insert into STADION values(201, 101, 'ArenA', 'Arenaweg 10', 50000, '05-03-1990');
However when I tried to put data into my 3rd table it gave me a syntax error near "301".
insert into TECHNISCHDIRECTEUR(301, 101, 'Michael Kinsbergen', 'Kalverstraat 18', 120000.13,
'Nederlands', 'Man', '03-09-1960');
What could it be?
You're missing the keyword values:
insert into TECHNISCHDIRECTEUR values(301,...

Resources