Two Days Ago
The version of EF Migrations discussed in this article is 5.0.20627. The version of Quino is less relevant: the features discussed have been supported for years. For those in a hurry, there is a tl;dr near the end of the article.
We use Microsoft Entity Framework (EF) Migrations in one of our projects where we are unable to use Quino. We were initially happy to be able to automate database-schema changes. After using it for a while, we have decidedly mixed feelings.
As developers of our own schema migration for the Quino ORM, we’re always on the lookout for new and better ideas to improve our own product. If we can’t use Quino, we try to optimize our development process in each project to cause as little pain as possible.
EF Migrations and branches
We ran into problems in integrating EF Migrations into a development process that uses feature branches. As long as a developer stays on a given branch, there are no problems and EF functions relatively smoothly.
However, if a developer switches to a different branch—with different migrations—EF Migrations is decidedly less helpful. It is, in fact, quite cryptic and blocks progress until you figure out what’s going on.
Assume the following not-uncommon situation:
- The project is created in the master branch
- The project has an initial migration BASE
- Developers A and B migrate their databases to BASE
- Developer A starts branch feature/A and includes migration A in her database
- Developer B starts branch feature/B and includes migration B in his database
We now have the situation in which two branches have different code and each has its own database schema. Switching from one branch to another with Git quickly and easily addresses the code differences. The database is, unfortunately, a different story.
Let’s assume that developer A switches to branch feature/B to continue working there. The natural thing for A to do is to call “update-database” from the Package Manager Console. This yields the following message—all-too-familiar to EF Migrations developers.
“Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending changes to a code-based migration or enable automatic migration. […]”
This situation happens regularly when working with multiple branches. It’s even possible to screw up a commit within a single branch, as illustrated in the following real-world example.
- Add two fields to an existing class
- Generate a migration with code that adds two fields
- Migrate the database
- Realize that you don’t need one of the two fields
- Remove the C# code from the migration for that field
- Tests run green
- Commit everything and push it
As far as you’re concerned, you committed a single field to the model. When your co-worker runs that migration, it will be applied, but EF Migrations immediately thereafter complains that there are pending model changes to make. How can that be?
Out-of-sync migrations != outdated database
Just to focus, we’re actually trying to get real work done, not necessarily debug EF Migrations. We want to answer the following questions:
- Why is EF Migrations having a problem updating the schema?
- How do I quickly and reliably update my database to use the current schema if EF Migrations refuses to do it?
The underlying reason why EF Migrations has problems is that it does not actually know what the schema of the database is. It doesn’t read the schema from the database itself, but relies instead on a copy of the EF model that it stored in the database when it last performed a successful migration.
That copy of the model is also stored in the resource file generated for the migration. EF Migrations does this so that the migration includes information about which changes it needs to apply and about the model to which the change can be applied.
If the model stored in the database does not match the model stored with the migration that you’re trying to apply, EF Migrations will not update the database. This is probably for the best, but leads us to the second question above: what do we have to do to get the database updated?
Generate a migration for those “pending changes”
The answer has already been hinted at above: we need to fix the model stored in the database for the last migration.
Let’s take a look at the situation above in which your colleague downloaded what you thought was a clean commit.
From the Package Manager Console, run
add-migration foo to scaffold a migration for the so-called “pending changes” that EF Migrations detected. That’s interesting: EF Migrations thinks that your colleague should generate a migration to drop the column that you’d only temporarily added but never checked in.
That is, the column isn’t in his database, it’s not in your database, but EF Migrations is convinced that it was once in the model and must be dropped.
How does EF Migrations even know about a column that you added to your own database but that you removed from the code before committing? What dark magic is this?
The answer is probably obvious: you did check in the change. The part that you can easily remove (the C# code) is only half of the migration. As mentioned above, the other part is a binary chunk stored in the resource file associated with each migration. These BLOBS are stored in the table
_MigrationHistory table in the database.
How to fix this problem and get back to work
Here’s the tl;dr: generate a “fake” migration, remove all of the C# code that would apply changes to the database (shown below) and execute
update-database from the Package Manager Console.
This may look like it does exactly nothing. What actually happens is that it includes the current state of the EF model in the binary data for the last migration applied to the database (because you just applied it).
Once you’ve applied the migration, delete the files and remove them from the project. This migration was only generated to fix your local database; do not commit it.
Everything’s cool now, right?
Applying the fix above doesn’t mean that you won’t get database errors. If your database schema does not actually match the application model, EF will crash when it assumes fields or tables are available which do not exist in your database.
Sometimes, the only way to really clean up a damaged database—especially if you don’t have the code for the migrations that were applied there—is to remove the misapplied migrations from your database, undo all of the changes to the schema (manually, of course) and then generate a new migration that starts from a known good schema.
Conclusions and comparison to Quino
The obvious answer to the complaint “it hurts when I do this” is “stop doing that”. We would dearly love to avoid these EF Migrations-related issues but developing without any schema-migration support is even more unthinkable.
We’d have to create upgrade scripts manually or would have to maintain scripts to generate a working development database and this in each branch. When branches are merged, the database-upgrade scripts have to be merged and tested as well. This would be a significant addition to our development process, has maintainability and quality issues and would probably slow us down even more.
And we’re certainly not going to stop developing with branches, either.
We were hoping to avoid all of this pain by using EF Migrations. That EF Migrations makes us think of going back to manual schema migration is proof that it’s not nearly as elegant a solution as our own Quino schema migration, which never gave us these problems.
Quino actually reads the schema in the database and compares that model directly against the current application model. The schema migrator generates a custom list of differences that map from the current schema to the desired schema and applies them. There is user intervention but it’s hardly ever really required. This is an absolute godsend during development where we can freely switch between branches without any hassle.
Quino doesn’t recognize “upgrade” versus “downgrade” but instead applies “changes”. This paradigm has proven to be a much better fit for our agile, multi-branch style of development and lets us focus on our actual work rather than fighting with tools and libraries.
Downgrademethod that is generated with each migration, but perhaps someone with more experience could explain how to properly apply such a thing. If that doesn’t work, the method outlined above is your only fallback.↩
2 weeks Ago
1 month Ago
I know that pointing out errors in iTunes is a bit passé but Apple keeps releasing new versions of this thing without addressing the fundamental problems that it has as a synchronization client.
The software has to synchronize with hardware from only one manufacturer—the same one that makes iTunes. I’ll leave off complaints about the horrific, very old and utterly non-scaling UI and just regale you with a tale of a recent interaction in which I restored my phone from a backup. In that sense, it’s a “user experience”.
In this tale, we will see that two of the main features of the synchronization part of the iTunes software—backup and sync—seem to be utterly misinterpreted.
Spoiler alert: it all works out in the end, but it’s mind-boggling that this is the state of Apple’s main software after almost 15 years.
10 million new iPhones were sold over the weekend. Their owners will all have the pleasure of working with this software.
Restore from backup
Me: *attaches phone*
iTunes: Restore from backup?
iTunes: *shows almost full iPhone* There you go!
Me: Thanks! That was fast!
Me: Wait…my phone is empty (no apps, no music, no contacts)
iTunes: *blushes* Yeah, about that…
Me: *reconnects phone*
iTunes: *shows nearly empty iPhone* What’s the problem?
Me: Seriously, RESTORE FROM BACKUP (select EXACT SAME backup as before)
iTunes: On it! Sir, yes sir!
Me: OK. Apps are back; contacts are back. No music, iTunes? What part of the word “backup” is causing difficulties here?
iTunes: *blushes* (again) Ummm, dunno what happened there
Me: Fine. It was randomly selected anyway.
Me: Select random music from this playlist
iTunes: Here ya go!
iTunes: Nothing to do
iTunes: Seriously, dude, there’s nothing to do
Me: No music on phone. Do you understand the word “sync” differently as well? You know, like how you have trouble with the word “backup”?
Me: *notices that size of playlist exceeds capacity of iPhone*
Me: that’s 17GB of music. For a 16GB iPhone.
iTunes: Yep! Awesome, right?
Me: Is that why you won’t sync?
iTunes: Error messages are gauche. I don’t use them. Everything is intuitive.
Me: Fine. Reserve space when selecting music: 1GB (don’t need more extra space than that)
iTunes: NP! Here’s 15GB of music.
Me: Wait, what? You’re supposed to leave 1GB empty *of the available space* not the *total size of the device*
iTunes: Math is hard. … You do it.
Me: Fine. Reserve 4.2GB?
Me: Now I have a 28GB playlist.
iTunes: *pats self on back*
Me: Reserve 3.2GB … and “delete all existing” and “replace”? Now does it work?
iTunes: 9GB for you
Me: *tweaks settings 2 or 3 more times*
Me: Perfect. That was totally easy.
iTunes: On it! *hums to self*
Me: Why are you only syncing 850 songs when the playlist has 1700 of them?
iTunes: *continues humming*
Me: Fine. *wanders away*
iTunes: *syncing 250 more songs*
Me: What the hell?
iTunes: *syncs remaining songs*
Me: This is ridiculous
- Download the presentation
- Unzip to a local folder
index.htmlin a modern web browser (Chrome/Opera/Firefox work the best; IE has some rendering issues)
We learned a few very interesting things:
- PowerShell is pre-installed on every modern Windows computer
- You can PowerShell to other machines (almost like ssh!)
- Windows developers should definitely learn how to use PowerShell.
- Unix administrators who have to work on Windows machines should definitely learn how to use PowerShell. The underlying functionality of the operating system is much more discoverable via command line,
get-memberthan the GUI.
- You should definitely install ConEmu
- When running ConEmu, make sure that you start a PowerShell session rather than the default Cmd session.
- If you’re writing scripts, you should definitely install and use the ISE, which is an IDE for PowerShell scripts with debugging, code-completion, lists of available commands and much better copy/paste than the standard console.
- The PowerShell Language Reference v3 is a very useful and compact reference for beginners and even for more advanced users
The easiest way to integrate PowerShell into your workflow is to make it eminently accessible by installing ConEmu. ConEmu is a Windows command-line with a tabbed interface and offers a tremendous number of power-user settings and features. You can tweak it to your heart’s content.
- Download ConEmu (CodePlex); I installed version 140814, the most recent version marked as “beta”. There is no official release yet, but the software is quite mature.
- Install it and run it. I didn’t allow the Win + Num support because I know that I’d never use it. YMMV and you can always change your choice from the preferences.
- Show the settings to customize your installation. There are a ton of settings, so I listed the ones I changed below.
- Set the window size to something a bit larger than the standard settings, especially if you have a larger monitor. I use 120 × 40.
- Choose the color scheme you want to use. I’m using the standard PowerShell colors but a lot of popular, darker schemes are also available (e.g. Monokai).
- Check out the hotkeys and set them up accordingly. The only key I plan on using is the one to show ConEmu. On the Swiss-German keyboard, it’s Ctrl + ¨.
- The default console is not transparent, but there are those of us who enjoy a bit of transparency. Again, YMMV. I turned it on and left the slider at the default setting.
- And, finally, you can turn on Quake-style console mode to make it drop down from the top of your primary monitor instead of appearing in a free-floating window.
2 months Ago
- He’s Just Not That Into You (2009)
- A star-studded cast can’t save this utterly derivative and cliché script. Bradley Cooper, Jennifer Connelly, Kevin Connolly, Scarlet Johannson, Justin Long, Drew Barrymore, Jennifer Aniston and Ben Affleck. And Busy Phillips—of Freaks and Geeks fame—had a small role. This movie purports to dispel the myths of dating, marriage and male/female relationships. Though it may appear to do so superficially—at least it very clearly tells you that it is doing so—at a deeper level, it is no better than any other film in this genre. I don’t remember every minute of this 129-minute movie—you read that correctly, this so-called “chick flick” is over two hours long and never seems to end—but I’m almost 100% certain that it failed the Bechdel Test. It also fails other common tests: there are a dozen lead characters and they’re all white. The women all have low-level jobs—most work together in a cube farm and another is a struggling singer—while the men are all successful : one is a record executive, another owns/operates his own bar/restaurant, another is a successful real-estate agent and another’s job is unclear but he owns his own boat. The women are all kind of dependent on their men, whining about their inability to get married or find a guy. The men clearly don’t care. Not recommended.
- Brother (2000)
Takeshi Kitano directs himself in the starring role in this story of the journey to America of an exiled Yakuza gangster named Aniki Yamanoto. He is sparing in motion and speech but when he moves, he does so precisely and with great and often lethal force. He is also extremely shrewd at conquering territory in his newfound home, where the existing gangs seem to be less quick to pull triggers than he. The movie also stars a very young Omar Epps.
Yamamoto joins forces with another local Japanese gang and they commence expanding their territory. There are many execution scenes that delineate the new power divide. There are scenes of self-mutilation among the Yakuza that makes you wonder whether they’ll kill themselves off before their enemies can do it. They finally end up taking on the Mafia and things get really ugly. The scenes themselves are often very stylistic and pretty, despite the gruesome depictions in them.
It’s nicely filmed in what I’ve come to think of as the Japanese crime-drama style. Many of the shots feel like Grand Theft Auto Tokyo/San Francisco. Saw it in English and Japanese/Spanish with English subtitles. Recommended.
- Sexy Beast (2000)
This is an English crime movie starring Ben Kingsley as a thug named Don Logan sent to collect Ray Winstone’s character, Gad, to help execute a robbery. Gad has been living in Spain for years after retiring from the safe-cracking business. Logan doesn’t take no for an answer and he makes the most of his reputation as a ruthless henchman. Gad, his wife and his friend and wife are all extremely leery of Logan and give him a lot of leeway. Kingsley fills all the space he’s given with menace, although it’s a tight-rope of false menace versus the fear of the others, who just want to extricate themselves from this situation. They want the nightmare of Kingsley’s character to go away and he knows this, he feeds off of it.
Spoiler alert: Logan pushes them all too far and Gad’s wife ends up taking him out with a shotgun after which he taunts them from the ground, spitting blood and curses and epithets while he chokes out his last. Gad goes to England to do the job anyway, trying to cover tracks, but the head honcho there—Teddy, played by ian McShane—oozes just as much menace as Don Logan. I thought the film had a nice style—it was directed by Brian Glazer—and it reminded me a bit of some of Kubrick’s work. Recommended, but not highly.
- Frozen (2103)
The standard Disney princess-meets-boy movie has been transplanted to the great white North, presumably somewhere in … Iceland? Because of the trolls? Or Norway because of all of the names, like Olaf? Probably generically European, I guess. It’s all just one big place. The first act—about 40 minutes—is pretty insufferable. There is one forgettable musical number after another, with the most appalling lyrics.
And then, out of nowhere, the door to the sauna/shop cabin in the woods opens and we are introduced to the innkeeper, who seems snatched right out of the Emperor’s New Groove and is a breath of fresh—and funny—air in an otherwise odiously predictable movie. A movie made all the more unbearable by the back-to-back-to-back and seemingly endless crooning. The one song that really stood out was, of course, Olaf the snowman’s ode to summer, another slyly hilarious song made poignant by his utter obliviousness to the meaning of the words he’s singing. That twenty-minute segment in the middle could be extracted into a good short film.
What I’m calling the third act was just as predictable as the first act. How were the much-vaunted animations? The snow was well-done, I guess. The human figures were terrible, at least the female ones were. Has anyone else noticed that Disney has ended up depicting females as Bratz dolls instead of human-looking? The male characters were fine, although of course all conventionally handsome. Josh Gad as Olaf was a standout. The musical numbers and plot was 100% designed so that Disney doesn’t have to pay anyone to write the inevitable Broadway musical.
- The Waterboy (1998)
- It is neither an exaggeration nor necessarily a compliment to write that this is possibly Adam Sandler’s best comedy, or is at least in the running with Happy Madison.
- The Fantastic Mr. Fox (2009)
A wonderful stop-motion animation written and directed by Wes Anderson and based on a story by Roald Dahl. The film is unmistakably a Wes Anderson flick with the usual rogue’s gallery that includes Bill Murray, Owen Wilson, Willem Dafoe and Jason Schwartzman all lending their voices to characters. Meryl Streep lends her voice to Felicity Fox, Mr. Fox’s wife. Mr. Fox is voiced by George Clooney, who at times seems to be channeling Everett McGill from Oh Brother Where Art Thou. There were no musical numbers, which was a nice change of pace from Frozen, which was filled end-to-end with them.
The story follows a reprobate Mr. Fox who supplements a boring career as a newspaperman with a few last capers that involve stealing from three local farmers. The farmers respond with extreme prejudice and Mr. Fox’s capers end up dragging the whole local animal world into danger. His son, Ash, is kind of strange (played by Schwartzman, of course) and in competition with his cousin, who’s come to live with them for a while and who is quite an accomplished athlete much more in the vein of his uncle than his uncle’s son (Ash) could ever be. The first and second acts were quite strong while the final act kind of dragged a bit, but it was a madcap and zany animated feature that is well worth the time. Recommended.
- The Jungle Book (1967)
- The classic Disney movie has its own cloying bits of story, but the feel of the film was somehow much more artistic than Disney’s later efforts (like Frozen, reviewed above). The songs are great and include more than a few classics and more memorable characters than most of Disney’s princess-drenched pap. Baloo, Bagira (Baggy), Ka and King Louie all stand out—although what also stands out is that there almost no female characters at all. The film’s not without its problems, but the musical numbers are something to look forward to rather than to dread. Ka stretches all over the trees and forms stairs and wheels out of his coils for Mogli to fall into and it’s somehow nicer than the CGI animations we have today. Recommended.
- Ponyo (2008)
- This is a wonderfully drawn Japanese cartoon that has a plot made for six–year-olds. It was an adorable plot but it didn’t give adults much to go on. I could only find a dubbed version (or perhaps the original was in English?) because I usually avoid Hollywood dubbing of Japanese anime like the plague. Ponyo’s father was voiced by Liam Neeson—of all people—and his rather distinctive voice took me a bit out of the aesthetic of the film. Highly recommended for small kids but not anywhere on the level of a Spirited Away or Howl’s Moving Castle for adults.
- Singin’ in the Rain (1952)
- Gene Kelly, Donald O’Connor, Debbie Reynolds and Jean Hagen star in this movie about a silent-film company that makes the transition to sound. Set in 1927, the feel is quite over-the-top and it’s hard to tell whether it feels dated because the film is from 1952 or whether it feels dated because it’s pretending that it comes from 1927. I don’t know if it’s worth 8.4 out of 10 on IMDb but it definitely has its moments and it’s definitely worth being called a classic. It was highly entertaining and there was a number near the end that was positively Daliesque. There were so many fantasies within fantasies that I think we were three inception-levels down if not four. O’Connor’s “Make ‘em laugh” routine is marvelous and Kelly’s scene opposite Hagen where they act out a scene in a movie while discussing her having gotten the girl he likes fired was pretty inspired.
- Walk of Shame (2014)
- Elizabeth Banks is charming in this movie, which goes a long way to papering over the otherwise glaring cracks in the script. James Marsden is also quite good as the sheepish, earnest one-night-stand. It’s a popcorn comedy that ended up being fun enough with an utterly unsurprising ending. Bill Burr had a cameo as a police officer but was unnecessarily brutal and not funny at all. Not recommended but also not not recommended.
- Prisoners (2013)
- Jake Gyllenhall and Hugh Jackman are the two leads in this well-made film about child abduction. Hugh Jackman plays the father, driven mad with grief over the loss of his daughter. Jake Gyllenhall plays the police officer assigned to the case. Both are very, very intense. Maria Bello played Jackman’s wife, who arguably handled the abduction even worse than her husband. Paul Dano and Melissa Leo were both very, very good but I won’t mention their roles so as not to spoil anything. The ending was a bit lame, in that it made what should have been routine police-work looks like nigh-miraculous leaps of intuition. Still, highly recommended.
- The Lego Movie (2014)
A movie for the A.D.D. generation. This movie is, on the surface, an explosion of color, sound and scene and context changes. Below the surface, there might be some social critique, but it is quickly buried beneath a relentless avalanche of nearly incomprehensible action. Imagine yourself clinging to the edge of a rubber tube, smashing your way down category–5 rapids, holding on for dear life and trying desperately to anticipate what’s going on. That helpless feeling you have—if you’ve imagined properly—is exactly how you’ll feel watching this movie.
When it slows down for some insipid dialogue, delivered during a Matrix-like pause, you’re ever so thankful that the onslaught on your brain has, for whatever reason, abated. You’re so happy that you don’t even care that the one-liners are carefully vetted to satisfy all audiences and censors and harbor no true critique. This movie is rated PG and is therefore open for kids of all ages—who are we kidding?—but in the first fifteen minutes, we see a man have half of his personality erased for failing to prove his allegiance by incapacitating his own parents. As the lead lego-man said, “I’m just gonna come right out and say this: I have no idea what this place is or what’s going on—at all.”
- Big Night (1996)
- Stanley Tucci and Tony Shalhoub play Italian brothers with a restaurant in New Jersey that is on the verge of closing because they cook authentic Italian food and the customers are sparse and mostly “Philistines” (as Tony Shalhoub says). This seemed a promising film, but I was unable to finish watching it. More details in a future edition.
- Captain America: The Winter Soldier (2014)
This is a very solid spy movie. There’s good continuity from the first movie and Chris Evans and Scarlet Johansson reprise their respective roles well. I liked almost everything about this movie and look forward to more in the Captain America series. The effects were well-integrated and not too distracting right up until the very elegant ending credits.
I’m not so happy with Samuel L. Jackson’s continued ham-handed portrayal of Nick Fury, though I admit that I may not be remembering just how much of a jingoistic jerk Fury was in the comic books. My admittedly old memories of him all see him as “cool”, whereas he was probably exactly the proponent of the security state that Jackson portrays him to be. Robert Redford is also way over the top and it’s hard to tell whether he’s deliberately being over the top in his portrayal of a right-wing power-hungry super-criminal and where I’m so out of touch with US culture that I can’t tell that he’s just espousing very mainstream views. The main premise involving H.Y.D.R.A. was well–thought-out and executed. Highly recommended.
- My Cousin Vinnie (1992)
- It is absolutely clear from the first time she opens her mouth why Marisa Tomei earned an academy award for this movie. Joe Pesci is good, Ralph Macchio is…ok, but Marisa Tomei is spectacular. The whole movie is quite a clever and nicely made courtroom drama that pokes fun at everyone—although the American South arguably gets the worse and more unfair treatment. They’re pretty much all hicks, according to this movie. Still, there are so many good lines and clever turns that it’s definitely worth watching. Highly recommended.
- District 13 (2004) (fr)
- This French parkour film stars one parkour star—David Belle, ostensibly the inventor of the sport—and one stuntman, Cyril Raffaelli, both of whom deliver some nicely choreographed fight scenes. The first act ends on a very cool note, with Belle delivering the coup de grâce. The plot is mostly predictable but it’s quite well-made and the parkour scenes are worth the price of entry. Some of the thugs are less one-dimensional than usual (e.g. K2) and the sub-titles are idiomatically rather than literally translated. There’s a bit of a twist at the end that’s not bad. Recommended for fans of the genre.
- I’m Gonna Git You Sucka (1988)
- As the title suggests, this is a send-up of blaxploitation movies of the 70s, starring a couple of the Wayans brothers as well as Jim Brown, Bernie Casey and Isaac Hayes. Some parts work; most don’t (at least anymore…the movie hasn’t really aged well). The outside sets are kinda nice as are some of the cars. When Kung Fu Joe (played by Steve James) is pulled over, he gets out of his Nissan, which tells him that his “door is ajar”—that took me back because we had a ‘84 Nissan Maxima that did the same thing. It has its moments—a 23-year–old Chris Rock plays a bit part as “Rib Joint Customer”, inventing the temporarily popular “I’ll have one rib” catchphrase. Not really recommended unless you need to fill a hole in your silly 80s movies education.