Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrimaryKey auto-increment concept is not working in persistencejs #186

Open
bairaginath opened this issue Apr 24, 2016 · 0 comments
Open

Comments

@bairaginath
Copy link

var persistence = require('persistencejs');
var persistenceStore = persistence.StoreConfig.init(persistence, { adaptor: 'mysql' });
persistenceStore.config(persistence, 'localhost', 3306, 'nodedb', 'root', 'root');

var session = persistenceStore.getSession();

var User = persistence.define('user', {
email: "TEXT",
password : "TEXT",
first_name : "TEXT",
last_name : "TEXT"
});

var user = new User({email:'[email protected]',password : 'world',first_name : "world",last_name:'world'});

session.add(user);
session.transaction(function(tx) {
session.flush(tx,function(result){

    console.log(result.insertId);
});

});

session.close();

it alway create random primary key and also some time duplicate key problem occurs.
below the following sql create query :

CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT,
email varchar(45) NOT NULL,
password varchar(45) NOT NULL,
first_name varchar(45) DEFAULT NULL,
last_name varchar(45) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant