Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Learning Resources

Why don't just use SQL without an ORM?

I tried it out and I thought the process was much simpler, especially after learning the SQL syntax in a couple of the previous videos in the full-stack course, just curious as I don't see so much advantages using a ORM if you like writing SQL.

1 Answer

Anna Pichugina
Anna Pichugina
25,364 Points

Hey Caj,

Totally agree with you that once you get the hang of SQL it can seem like learning an ORM is just extra work. I've been thinking about this in the context of a project at work, where we use Django and an SQL database. The nice thing about using Django ORM to interact with the database is that it'll write the sql for you and interpolate values into the query, which can get a little tricky if you're trying to do batch queries and such with raw sql and psycopg2. And it also destructures the values you get from the database so you can use them like any other python variable in your code.

The other thing Django does, which is pretty neat, is any time you change your models it'll write a migration file that documents the changes to the database and more importantly includes code to reverse the changes, which is really important for version control and if you're trying to sync changes across your local version of a project and a deployed version on a server, as well as if you want to reverse any changes down the line.

Of course Django also has a lot of built-in safety features, like it'll automatically set your tables up with unique id's which is good practice but if you're doing raw sql it's not going to stop you from setting up a table without them. I think it also automates some performance improvements in the database like indexing and vacuuming.