-
Notifications
You must be signed in to change notification settings - Fork 2k
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
PostgreSQL Error: Incompatible columnType
for auto-incrementing column ("id")
#4599
Comments
@shobhitsinghal624 Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
I had the same issue. As a workaround it helped to downgrade sails-postgresql to version 1.0.0 |
@shobhitsinghal624 Not sure if explicitly adding the join table will help, but it looks like that where it might be getting stuck generating the schema stuff. https://sailsjs.com/documentation/concepts/models-and-orm/associations/through-associations Basically, create a new model (I tried with module.exports = {
attributes: {
members:{
model:'user'
},
teams: {
model: 'team'
}
}
} Then make sure the existing models know to use this join table, ie in User.js teams: {
collection: 'Team',
via: 'members',
through: 'through' // or whatever you call it
}, Then also in Team.js Then I Team.find({}).populate('members').then(r => console.log(JSON.stringify(r, null, 2)))
[
{
"members": [
{
"createdAt": 1552678830790,
"updatedAt": 1552678830790,
"id": "a",
"name": "bob"
},
{
"createdAt": 1552678839204,
"updatedAt": 1552678839204,
"id": "b",
"name": "tom"
}
],
"createdAt": 1552678892003,
"updatedAt": 1552678892003,
"id": "NYC",
"name": "New York Nuggins"
}
] 🐛 FWIW adding the "through model", but not linking it to the other two models with the Edit: I tried this with Sails 1.1.0 / Node v8.15.0 but I experienced your described errors with |
@texh, |
@raqem Starting from I suppose I was hinting that the changes I made worked in my environment, but other weird things may happen if OP is running v10 |
I think this could be an issue with whatever builds the "join table" for the many-to-many relationship & happens before If you take a look at the data for the user-defined models that's being fed into buildSchema, the attribute's 'columnType's are things like Adding something like the following around here gets the app lifted & tables created, but idk if it's The Right Way™. I think integer should probably have been translated to '_numberkey' before it gets this far 🤷♂️ case 'integer': computedColumnType = (attribute.autoIncrement ? 'SERIAL' : 'INTEGER'); break; |
@shobhitsinghal624 would have to dig into the code a bit more to confirm this, but I suspect that adding a custom definition for one of the attributes in (btw, any particular reason why you're overriding the |
@rachaelshaw just tried with I'm unable to use consistent |
@shobhitsinghal624 just realized the error is coming from the join model, which is using the default settings for Also, talked to @mikermcneil about this one, and he suggested that, instead of overriding the ID settings, it would be a good idea to use a different (custom) attribute for the Here's a similar issue that you might find helpful: #4542 |
@rachaelshaw: Found another workaround for this issue. First, the underlying problems that lead to this issue:
Workaround is to set default
This leads to |
@shobhitsinghal624 thank alot for revisiting this issue and providing your work around. Hopefully this can help others in the future. |
thank you @shobhitsinghal624. I am seeing the exact same issue and your workaround helped. In my app I heavily rely on uuids for id's. Since I am often mixing instances of different model types. |
Sails version: 1.1.0
Node version: v10.12.0
NPM version: 6.8.0
DB adapter name: N/A
DB adapter version: N/A
Operating system: macOS
I'm getting this error when I try a many-to-many association with
id
asstring
type is both the models. No errors when at least one model has anid
of typenumber
.Error:
Steps to reproduce the issue provided below.
Create models with many-to-many association:
Use PostgreSQL in
config/datastores.js
:Make sure default attributes are unchanged in
config/models.js
:Run
npm i sails-postgresql --save
to installsails-postgresql
Run
sails lift --drop
to get the error.Full error log:
The text was updated successfully, but these errors were encountered: