8

In ASP.NET there is entity framework or something called "database first," where entities are generated from an existing database. Is there something similar for Django?

I usually work with a pre-existing database that I need to create a backend (and subsequently a front end) for. Some of these relational databases have many tables and relations so manually writing models isn't a good idea. I've scoured Google for solutions but have come up relatively empty handed.

2 Answers 2

10

You can use the information on this link.

python manage.py inspectdb > models.py

https://docs.djangoproject.com/en/3.0/howto/legacy-databases/ It depends on your database, but I've worked with it and is good.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like there's one built into Django.. Not sure how I missed that in two days searching but I'm guessing "database first" is really only an ASP.NET thing. Search terms... I'll take a look and mark as correct if I have no follow ups. Thanks!
3

The default in Django is a Code First-type approach where the Django framework engine creates a Db for you based on your models and uses migrations to update the Db with model changes (like Code First). https://docs.djangoproject.com/en/1.11/intro/tutorial02/

What you're describing sounds like a Database First approach in the .Net world. Integrating Django with a legacy database: https://docs.djangoproject.com/en/1.11/howto/legacy-databases/

1 Comment

.NET has Code First as well with EF, msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx . Just FYI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.