当前位置:网站首页>How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
2022-07-05 04:17:00 【French red wine sweet】
problem :
I'm creating a bunch of migrations, some of which are standard "create table" or "modify table" migrations, and some of which modify data. I am creating a series of migrations , Some of them are standard “ Create table ” or “ Modify table ” transfer , Some of these migrations modify data .I'm using my actual ActiveRecord models to modify the data, a la: I am using my actual ActiveRecord Model to modify data ,a:
Blog.all.each do |blog| update_some_blog_attributes_to_match_new_schemaend
The problem is that if I load the Blog class, then modify the table, then use the Blog class again, the models have the old table definitions, and cannot save to the new table. The problem is , If I load Blog class , Then modify the table , Then use it again Blog class , Model has old table definition , And cannot be saved to a new table .Is there a way to reload the classes and their attribute definitions so I can reuse them? Is there any way to reload classes and their attribute definitions , So that I can reuse them ?
Solution :
Reference resources : https://stackoom.com/en/question/qEv边栏推荐
- A solution to the problem that variables cannot change dynamically when debugging in keil5
- [brush questions] BFS topic selection
- 如何优雅的获取每个分组的前几条数据
- Open graph protocol
- Common features of ES6
- [untitled]
- [phantom engine UE] realize the animation production of mapping tripod deployment
- 机器学习 --- 决策树
- Looking back on 2021, looking forward to 2022 | a year between CSDN and me
- Use of vscode software
猜你喜欢
Threejs Internet of things, 3D visualization of farms (II)
Why can't all browsers on my computer open web pages
MacBook installation postgresql+postgis
Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
“金九银十”是找工作的最佳时期吗?那倒未必
SPI read / write flash principle + complete code
About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
Threejs realizes sky box, panoramic scene, ground grass
What is test development? Why do so many companies hire test developers now?
MacBook安装postgreSQL+postgis
随机推荐
As soon as I write the code, President Wang talks with me about the pattern all day
Why can't all browsers on my computer open web pages
[phantom engine UE] the difference between running and starting, and the analysis of common problems
小程序中实现文章的关注功能
Clickpaas low code platform
Rust blockchain development - signature encryption and private key public key
Containerd series - detailed explanation of plugins
Uni app common functions /api
[thingsboard] how to replace the homepage logo
3. Package the bottom navigation tabbar
【虚幻引擎UE】实现测绘三脚架展开动画制作
PR video clip (project packaging)
Un réveil de l'application B devrait être rapide
Machine learning -- neural network
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
Learning MVVM notes (1)
快手、抖音、视频号交战内容付费
This is an age of uncertainty
阿里云ECS使用cloudfs4oss挂载OSS
provide/inject