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

Use defaults provided in entity definition decorators #6846

Closed

Conversation

jougene
Copy link
Contributor

@jougene jougene commented Oct 4, 2020

Imagine then we already have some database with no default provided in schema. But in entity(model) definition we want to determine default value, without touching database schema (default modification on big table can take a very long time).
Now when you have default value provided in Column decorator (@Column({ default: 'default_value'})) but not defined in database schema cause error `null value in column <column_name> violates not-null constraint. But honestly I wait that this value can be inserted with "default_value" value. So I prepare repository with this issue reproduce

And make a pr that fix this issue.

@pleerock
Copy link
Member

pleerock commented Oct 5, 2020

default in @Column is all about change in the database schema. I don't see a point to confuse things and introduce this change. If you don't need to change a database schema and instead just want to write some value, just use hooks or preset value before save.

@imnotjames
Copy link
Contributor

There are a number of ways to do this that don't break assumptions made about how typeorm interacts with the database.

I'm also gonna be a 👎 here - if you need this functionality please use other mechanisms to make it happen. You can even pull the default value from the columns as part of the model initialization.

@imnotjames imnotjames closed this Oct 20, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants