NestJs migrations with TypeORM 0.3 (latest) - How to set it up from scratch using Datasource

  Рет қаралды 49,088

Amitav Roy

Amitav Roy

Күн бұрын

Пікірлер: 175
@irfandyjip3246
@irfandyjip3246 Жыл бұрын
Saved for myself 12:19 Start talking about Migration 19:09 Migrations script
@amitavroydev
@amitavroydev Жыл бұрын
Interesting
@debadipti
@debadipti 2 жыл бұрын
You saved me from a lot of pain since ages!! Thank you !
@amitavroydev
@amitavroydev 2 жыл бұрын
Glad I could help!
@mariemmatri8743
@mariemmatri8743 Жыл бұрын
Thank you so much! I also liked how you figured out the issues in the video without cutting the video
@amitavroydev
@amitavroydev Жыл бұрын
Thanks
@CaminoConDiego
@CaminoConDiego Жыл бұрын
Dude! Thanks a lot seriously! This video must be at Nestjs and Typeform docs!!! Can not believe that I almost lost the day trying to find a way to create my migration
@amitavroydev
@amitavroydev Жыл бұрын
Good to know it helped you
@serbanzidaru943
@serbanzidaru943 8 ай бұрын
Thank you for this. I spent 3 hours on the official nestjs course and wasn't able to run the migrations. With your video literally 15 minutes and it works perfect. Life saver.
@amitavroydev
@amitavroydev 8 ай бұрын
That's great to head. Thanks for the comment
@MrDiGrayMan
@MrDiGrayMan Жыл бұрын
I've spent hours reading nest js and typeorm docs, and finaly found this video. Eveything works perfect, thank you!
@amitavroydev
@amitavroydev Жыл бұрын
Great to know it helped you
@nealfarrand1246
@nealfarrand1246 2 жыл бұрын
This was very helpful. Thanks for putting this together. It was very clear to understand.
@amitavroydev
@amitavroydev 2 жыл бұрын
Great to hear!
@angeloem83
@angeloem83 Жыл бұрын
No amount of words can explain how thankful I am. Umetisha chief...
@amitavroydev
@amitavroydev Жыл бұрын
Thank you so much 🙏
@joaovitor-mc5co
@joaovitor-mc5co Жыл бұрын
Thanks for the explanation, this perfectly resolve my problem with migrations in the TypeORM.
@amitavroydev
@amitavroydev Жыл бұрын
Good to know
@khaledali777
@khaledali777 Жыл бұрын
I have been struggling to make it happen. You made my day. 👍
@amitavroydev
@amitavroydev Жыл бұрын
Glad I could help
@YonatanVigilioUsa
@YonatanVigilioUsa 2 жыл бұрын
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command.
@amitavroydev
@amitavroydev 2 жыл бұрын
OK
@rjaysharma3097
@rjaysharma3097 Жыл бұрын
I getting the same issue. Are you able to solve it?
@victorm9131
@victorm9131 Жыл бұрын
Extremely helpful video. Thanks a lot!
@amitavroydev
@amitavroydev Жыл бұрын
You are welcome my friend
@ebukaokoye5286
@ebukaokoye5286 2 жыл бұрын
Thanks a lot, i have been running around looking for a solution to my migration bugs and you helped me fix them, i appreciate.
@amitavroydev
@amitavroydev 2 жыл бұрын
Glad I could help
@MayabiLinux
@MayabiLinux 9 ай бұрын
How do I load the data source , and typeOrmModule.forRoot from same .env file ? anyone has any idea or can give me some hints please ? Thanks
@amitavroydev
@amitavroydev 8 ай бұрын
Haven't tried that yet
@EzequielBinker
@EzequielBinker Жыл бұрын
"No changes in database schema were found - cannot generate a migration" issue. Did anyone solve this ? I'm using typeorm 0.3. Thanks
@amitavroydev
@amitavroydev Жыл бұрын
This reply from Yaseen shaik might work 1. Stop all the executions. 2. delete the generated sql file. 3. do "npm run start:dev" or "yarn start:dev" 4. Open another terminal in the root directory 5. and enter the migration:generate command as shown in the video. Hope this solve your issue.
@amerhamed1729
@amerhamed1729 7 ай бұрын
Hi sir I don't know why but when i try to run the second command of migration generate it give me to create an other tables not Alter
@amitavroydev
@amitavroydev 7 ай бұрын
Look at the migration table. Do you already have entries
@amerhamed1729
@amerhamed1729 7 ай бұрын
@@amitavroydev yes share the code please
@golu8045
@golu8045 Жыл бұрын
Hello sir, can you share a github repo link of this code? because I am getting an error "No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command" or please make a video how to solve this issue
@amitavroydev
@amitavroydev Жыл бұрын
I don't have a Github repo for just this video
@davisperezguzman3384
@davisperezguzman3384 Жыл бұрын
could you solve it? I sell the same
@golu8045
@golu8045 Жыл бұрын
@@davisperezguzman3384 if you are using typeorm@0.3.12 then downgrade the version because it is a bug of typeorm for windows laptops.
@sarunmrzn
@sarunmrzn Жыл бұрын
Can you inject the config service to datasource for env vars? I can only get it working with dotenv package, it'd be nice if there was a workaround by using config service itself
@amitavroydev
@amitavroydev Жыл бұрын
Still couldn't make it happen
@nucleus8706
@nucleus8706 Жыл бұрын
How did you do it with dotenv?
@okekunleoluwatobiloba9184
@okekunleoluwatobiloba9184 2 жыл бұрын
i'll be honest with you, ATM, you are my GOAT!!!!!!!!!
@amitavroydev
@amitavroydev 2 жыл бұрын
Thank you so much
@vladislavderkach2647
@vladislavderkach2647 Жыл бұрын
Thank you, bro. It was very helpful!
@amitavroydev
@amitavroydev Жыл бұрын
Glad it helped!
@rafaeldossantostiburcio509
@rafaeldossantostiburcio509 2 жыл бұрын
Great video, congratulations
@amitavroydev
@amitavroydev 2 жыл бұрын
Thank you!
@iamabhirupdatta
@iamabhirupdatta Жыл бұрын
Hey, i am having issues when doing this in a express-ts project without nextjs. I have a src folder which contains ts files and a dist folder which output js files in same name as ts except with .js extension. Everything is working except the migrations commands. "start": "cross-env NODE_ENV=dev node dist/server.js", "typeorm": "npm run start && ts-node ./node_modules/typeorm/cli", "typeorm:generate-migration:win": "npm run typeorm -- -d ./src/api/database/initialize.ts migration:generate ./dist/api/database/migrations/FirstMigration" The commands run but the migration file doesnot generate. Please help
@amitavroydev
@amitavroydev Жыл бұрын
Hmm, I haven't looked at the integration of TypeORM with Express yet. However, tell me one thing - does it work properly if sync is set to true?
@jesuscordoba1117
@jesuscordoba1117 Жыл бұрын
Thank you very much, very useful and worked perfectly.
@amitavroydev
@amitavroydev Жыл бұрын
Glad it helped
@sagargopale8718
@sagargopale8718 9 ай бұрын
I do not get DataSourceOptions in typeorm module. What version are you using for @nestjs/typeorm and typeorm?
@amitavroydev
@amitavroydev 9 ай бұрын
I am using 0.3
@jaganath15
@jaganath15 Жыл бұрын
Thanks❤, it's working like a charm
@amitavroydev
@amitavroydev Жыл бұрын
Welcome 😊
@vijayendralolla
@vijayendralolla Жыл бұрын
Your videos are Great. One request is to make another series for writing tests using jest (for this Quiz project)
@amitavroydev
@amitavroydev Жыл бұрын
will try
@kassimolawale4223
@kassimolawale4223 4 күн бұрын
Thank you I was able to fix my issue with migration
@amitavroydev
@amitavroydev Күн бұрын
That's good to know.
@nicolagabriel8520
@nicolagabriel8520 Жыл бұрын
How about if i want to use config service for env when creating a datasource?
@amitavroydev
@amitavroydev Жыл бұрын
Need to try that
@adesegunadebayo
@adesegunadebayo Жыл бұрын
I have been pulling my hair with the breaking changes from typeorm >= 0.3 versions, I'll update this thread if it comes out successful!
@amitavroydev
@amitavroydev Жыл бұрын
I am trying to do the same. Some issue with typeorm and nestjs configuration
@Айдер-т5з
@Айдер-т5з 2 жыл бұрын
This is a great guide. I spent a lot of time setting up migrations. like, share, subscribe
@amitavroydev
@amitavroydev 2 жыл бұрын
Thanks my friend
@romanpredein
@romanpredein Жыл бұрын
I spent three days with the documentation to no avail. I should have gone here first. Thanks!!!
@amitavroydev
@amitavroydev Жыл бұрын
Thanks for the comment. Do subscribe if you’re not already a subscriber 🙏
@shalandichannel
@shalandichannel Жыл бұрын
do you why i might get this error: Error during migration generation: TypeError at Reflect.getMetadat sounds familiar ?
@shalandichannel
@shalandichannel Жыл бұрын
i am using version 0.3 of typeorm
@amitavroydev
@amitavroydev Жыл бұрын
Well I am not getting that error Could be some configuration issue
@amitavroydev
@amitavroydev Жыл бұрын
What node version are you on
@saif_haq_
@saif_haq_ Жыл бұрын
"No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command" Please tell how to solve this.......... the only difference in my code is that i'm using Postgres and i've used graphql instead of rest api
@amitavroydev
@amitavroydev Жыл бұрын
This solution by YaseenShaik might work 1. Stop all the executions. 2. delete the generated sql file. 3. do "npm run start:dev" or "yarn start:dev" 4. Open another terminal in the root directory 5. and enter the migration:generate command as shown in the video. Hope this solve your issue.
@JoeJoseph79
@JoeJoseph79 10 ай бұрын
How do I implement seeding here
@amitavroydev
@amitavroydev 10 ай бұрын
Any problem with the original video that I have created on Seeder?
@nucleus8706
@nucleus8706 2 жыл бұрын
if you encounter cannot find ./app.controller - something is wrong in your dist file. I ran prebuilt command to generate dist folder and it worked.
@amitavroydev
@amitavroydev 2 жыл бұрын
Thanks for the help buddy
@nucleus8706
@nucleus8706 2 жыл бұрын
@@amitavroydev I must thank you. Your video made things more clear that I was struggling with. How do you load env credentials in datasource with config service?
@souleymanetoure670
@souleymanetoure670 Жыл бұрын
You are amazing !
@amitavroydev
@amitavroydev Жыл бұрын
Thank you
@youwontbelievewhathappensnext
@youwontbelievewhathappensnext 22 күн бұрын
Splendid thank you
@amitavroydev
@amitavroydev 20 күн бұрын
Thanks 👍
@ongo9977
@ongo9977 Жыл бұрын
how to read database config from env file
@amitavroydev
@amitavroydev Жыл бұрын
There is already a video in this series where I have done that. You can check that.
@ongo9977
@ongo9977 Жыл бұрын
@@amitavroydev tks you
@avivlevinson6245
@avivlevinson6245 Жыл бұрын
Thank you very much! In the newer versions of TypeORM, the @EntityRepository() decorator has been deprecated. any idea how to solve that ?
@amitavroydev
@amitavroydev Жыл бұрын
Normal queries I guess. Haven't checked in details yet
@islamicworld5086
@islamicworld5086 Жыл бұрын
Excellent work
@amitavroydev
@amitavroydev Жыл бұрын
Many thanks
@TheTomislavb
@TheTomislavb 2 жыл бұрын
Great video, thank you
@amitavroydev
@amitavroydev 2 жыл бұрын
You are welcome!
@orjiemmanuel1418
@orjiemmanuel1418 Жыл бұрын
Thank you so much for this video, mine was able to generate the migration file after a created a new entity that wasn't in the database but when I run migration:run command I get "No Migrations are pending"
@orjiemmanuel1418
@orjiemmanuel1418 Жыл бұрын
I made some adjustment in my data-source file and it worked just fine!
@amitavroydev
@amitavroydev Жыл бұрын
Good to know it finally worked
@shivam.gupta25
@shivam.gupta25 10 ай бұрын
@@orjiemmanuel1418 what adjustments did you made
@eunjikim2u
@eunjikim2u 2 жыл бұрын
You saved me too!!! Thank you so much! You are genius!!! LOL
@amitavroydev
@amitavroydev 2 жыл бұрын
Glad I could help!
@malamhari_
@malamhari_ 2 жыл бұрын
Thanks, it helps me a lot
@amitavroydev
@amitavroydev 2 жыл бұрын
Glad to hear that!
@code-island
@code-island Жыл бұрын
Very Good Content
@amitavroydev
@amitavroydev Жыл бұрын
Thank you 🙏
@spoodermen2530
@spoodermen2530 Жыл бұрын
thanks! worked well for me.
@amitavroydev
@amitavroydev Жыл бұрын
Glad it helped
@zayyanabdillah7031
@zayyanabdillah7031 4 ай бұрын
is it mandatory to create datasource in root level?
@amitavroydev
@amitavroydev 4 ай бұрын
Not necessary.
@orkhanmammadli1
@orkhanmammadli1 7 ай бұрын
thanks a lot for your effort 👍
@amitavroydev
@amitavroydev 7 ай бұрын
You are welcome
@somebody-17546
@somebody-17546 8 ай бұрын
Where i can get code ?
@amitavroydev
@amitavroydev 8 ай бұрын
This is an isolated video. You can follow the video to get the code. However, the entire series code can be found here: my-lnk.com/2188012324
@_vlmdr
@_vlmdr Жыл бұрын
Help me a lot! Thanks man
@amitavroydev
@amitavroydev Жыл бұрын
Happy to help!
@goikarBaab
@goikarBaab Жыл бұрын
​ @Amitav Roy I am getting an error, when i run the migrations. It says there are no migrations to run, even though there are pending scripts in the DB. Can you please share the repo link for this codebase
@amitavroydev
@amitavroydev Жыл бұрын
Hi ivo costa, I don't have a repo just for this video because I started from the installation. Let me see, if I can work on a series and create a Repo like I have done for the older NestJs project.
@yuliakhitrukhina
@yuliakhitrukhina 9 ай бұрын
Nice, thanks!
@amitavroydev
@amitavroydev 9 ай бұрын
Welcome
@djaos-8326
@djaos-8326 Жыл бұрын
This work for postgresql?
@amitavroydev
@amitavroydev Жыл бұрын
haven't tried. but typeorm does work with pgsql, so I am assuming it should
@olgabaeva727
@olgabaeva727 Жыл бұрын
+1 for the "No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command" error ((
@yaseenshaik103
@yaseenshaik103 Жыл бұрын
1. Stop all the executions. 2. delete the generated sql file. 3. do "npm run start:dev" or "yarn start:dev" 4. Open another terminal in the root directory 5. and enter the migration:generate command as shown in the video. Hope this solve your issue.
@amitavroydev
@amitavroydev Жыл бұрын
Hope the solution worked
@amitavroydev
@amitavroydev Жыл бұрын
Thanks for the help
@islamicworld5086
@islamicworld5086 Жыл бұрын
God bless u sir
@amitavroydev
@amitavroydev Жыл бұрын
Thank you 🙏
@Katie-hb8iq
@Katie-hb8iq Жыл бұрын
Why on earth would they change this and not update their documentation? They just say, "Make sure to create a database config file and give it the path" and that's gotta be as vague as humanly possible.
@amitavroydev
@amitavroydev Жыл бұрын
IDK
@matheusrehbein4234
@matheusrehbein4234 Жыл бұрын
nice thanks... please add in the playlist
@amitavroydev
@amitavroydev Жыл бұрын
Added
@rudeadyet1992
@rudeadyet1992 Жыл бұрын
Thanks very useful. Also, what about Seeding? Is it the same as of you old tutorial.
@amitavroydev
@amitavroydev Жыл бұрын
Yes, it is
@sargonfromazupiranu6544
@sargonfromazupiranu6544 5 ай бұрын
Grate video! But how to insert default data?
@amitavroydev
@amitavroydev 5 ай бұрын
You need to use seeders
@yaumiadz
@yaumiadz Жыл бұрын
thx, it's useful af. like it
@amitavroydev
@amitavroydev Жыл бұрын
Glad it helped
@cesarkohl
@cesarkohl Жыл бұрын
TYVM!
@amitavroydev
@amitavroydev Жыл бұрын
YAW
@Fill-c6j
@Fill-c6j 9 ай бұрын
Thank you! solve my problem
@amitavroydev
@amitavroydev 9 ай бұрын
Glad that it worked
@Nageswararao93
@Nageswararao93 2 жыл бұрын
Thank you so much for the great video. Can you please do a video on how to run migrations(refersh database) for e2e testing?
@amitavroydev
@amitavroydev 2 жыл бұрын
Will try to first learn myself :)
@liammax7289
@liammax7289 Жыл бұрын
Can you givr us a tutorial for the new seeding please ?
@amitavroydev
@amitavroydev Жыл бұрын
Oh, I haven’t played with nestjs recently. Have been completely busy with the amazing stuff that has come up in the laravel ecosystem. Will check and try to do one video
@sriharsha186
@sriharsha186 Жыл бұрын
Everyone who gets this warning:'No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command' - This is either because you did not have Entity() decorator or because the table already exists in the DB. Remember, in the video, the table was first deleted before the command to run migrations was run
@amitavroydev
@amitavroydev Жыл бұрын
Thanks 👍
@ArkojeetMukherjee
@ArkojeetMukherjee Жыл бұрын
I dropped all my tables, still I have this message.
@ArkojeetMukherjee
@ArkojeetMukherjee Жыл бұрын
I have the @Entity() decorator, but still nothing.
@ArkojeetMukherjee
@ArkojeetMukherjee Жыл бұрын
Never mind, I solved it thanks I missed one part of it
@CaminoConDiego
@CaminoConDiego Жыл бұрын
this happened to me, take a look on your entities: ['dist/**/*.entity.js'], migrations: ['dist/db/migrations/*.js'], keys at dataSourceOptions object. it must look like the example
@alphaprimeacademy474
@alphaprimeacademy474 2 жыл бұрын
very helpful video
@amitavroydev
@amitavroydev 2 жыл бұрын
Glad it was helpful!
@the0FFH
@the0FFH Жыл бұрын
Thanks!!
@amitavroydev
@amitavroydev Жыл бұрын
Welcome
@ManojRai-k2x
@ManojRai-k2x Жыл бұрын
Very Helpful. What is the exact version of typeorm you are using in this video?
@amitavroydev
@amitavroydev Жыл бұрын
0.3
@sadamhussain5009
@sadamhussain5009 2 жыл бұрын
Great Video We are facing No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command
@amitavroydev
@amitavroydev 2 жыл бұрын
What the scenario? Ideally it would detect change by default if actually there is a change
@eduardokiriakos6255
@eduardokiriakos6255 Жыл бұрын
I got the same! Did you fix it?
@nicolassavenay4602
@nicolassavenay4602 Жыл бұрын
​@@eduardokiriakos6255 You can try to import migrations files as module (import { migrationName} from './path/to/migrationName';) and use it in the migrations array of dataSourceOptions: migrations: [migrationName]
@eduardokiriakos6255
@eduardokiriakos6255 Жыл бұрын
@@nicolassavenay4602 I did it that way and it works! Thanks! But I would like to find a better way to do it :(
@yaseenshaik103
@yaseenshaik103 Жыл бұрын
1. Stop all the executions. 2. delete the generated sql file. 3. do "npm run start:dev" or "yarn start:dev" 4. Open another terminal in the root directory 5. and enter the migration:generate command as shown in the video. Hope this solve your issue.
@aurelinemotouom620
@aurelinemotouom620 2 жыл бұрын
you saved me , A video of seeders please
@amitavroydev
@amitavroydev 2 жыл бұрын
Yes, that's in the pipeline. Have been working on the Electron series so got delayed. Will try to come up with that soon
@killxflip8547
@killxflip8547 Жыл бұрын
Everyone who gets this warning:'No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command', add the @Entity() docorator to your entity class
@amitavroydev
@amitavroydev Жыл бұрын
Thanks 🙏
@defaultName-gw1vg
@defaultName-gw1vg Ай бұрын
thank you
@amitavroydev
@amitavroydev Ай бұрын
You're welcome
@crescini.adrian
@crescini.adrian Жыл бұрын
Crack +10
@amitavroydev
@amitavroydev Жыл бұрын
Thanks
@ICOReviewtoken
@ICOReviewtoken Жыл бұрын
please give me source github bro
@amitavroydev
@amitavroydev Жыл бұрын
I don’t have code for just this video. You can refer to the main series. You will find the github code
@islamicworld5086
@islamicworld5086 Жыл бұрын
Thanks
@amitavroydev
@amitavroydev Жыл бұрын
Welcome
@javierrenteria3195
@javierrenteria3195 Жыл бұрын
can you share us the repo? thanks
@amitavroydev
@amitavroydev Жыл бұрын
The main series n Nest has a repo. For this particular video, I have not created a separate repo
@javierrenteria3195
@javierrenteria3195 Жыл бұрын
@@amitavroydev aha! Good to know it. Thanks!
TypeORM v0.3.x Migrations, queries, with NestJS!
28:37
Marius Espejo
Рет қаралды 39 М.
Путин ответил на ультиматум Трампа
7:25
Diplomatrutube
Рет қаралды 1,1 МЛН
ССЫЛКА НА ИГРУ В КОММЕНТАХ #shorts
0:36
Паша Осадчий
Рет қаралды 8 МЛН
Session Vs JWT: The Differences You May Not Know!
7:00
ByteByteGo
Рет қаралды 330 М.
NestJS TypeORM миграции
18:09
WebMogilevtsev
Рет қаралды 14 М.
NestJS + TypeORM Tutorial | Repositories, Relations, Migrations & More
1:06:30
Nestjs Migration Tutorial
19:09
Tenacity
Рет қаралды 13 М.
Typeorm Migrations
9:42
Ben Awad
Рет қаралды 41 М.
TypeScript Crash Course
52:27
Traversy Media
Рет қаралды 625 М.
Nestjs PostgreSQL CRUD REST API Example with Typeorm
25:56
ZestMade
Рет қаралды 16 М.