Django MSSQL Database Backend vs. Django PYODBC - python

I'm new at both Python and Django and still trying to figure out the best environment for my development. As far as I saw, there are 2 options available for establishing a connection to a MSSQL database which are:
Django MSSQL Database Backend: http://django-mssql.readthedocs.org/en/latest/
Django PYODBC: https://github.com/lionheart/django-pyodbc/
What I want to ask is the difference between those 2 options and their pros/cons over each other. Do they differ from each other especially in terms of performance and stability?
(I have only found the link below in stackoverflow but it was quite limited and outdated so I've wanted to ask another question. Sorry if there are any recent ones that I haven't seen yet.)
django-pyodbc vs django-mssql
Thank you.

I chose django-mssql when I started my project two years ago, as it is optimized specially for SQL Server whereas django-pyodbc relies on pyodbc which is a generic ODBC driver.
Of course there are some bugs, but the package is actively maintained. So far it does the job very well for me.
The main downsides :
Only runs on Windows (depends on pywin32 package)
Django version support far behind latest (current stable version supports Django 1.7, and development version is for Django 1.8...)
Migrations are a little buggy. You may have to alter generated sql by yourself in some cases.
django-pyodbc seems to support latest Django version and is cross-platform, however I have not found any positive opinion of people that use it in production back when I had to choose between the two.

Related

Django Version 1.8.3 SQL Server v13 is not supported

I'm new to this stuff so I apologize if this is in the wrong place. I've inherited a Debian 7.14 system that has Django version 1.8.3 and Python version 2.7.6. It has a connection to SQL Server. We've just upgraded to SQL Server 2016 and are now getting the error
Exception Type: NotImplementedError
Exception Value: Sql Server v13 is not supported.
How can I upgrade to a newer version of Django for this connection to work again? What version will work with SQL Server 2016? I'm thinking it would be a good idea to upgrade Debian version as well while I'm at it, but I'm unsure whether that will break this further.
Any insight or suggestions is greatly appreciated, I've done a ton of research and I'm out of places to turn.
Most likely you're using an outdated version of Django MSSQL database connector. According to its change log, starting with v1.8 the connector support MS SQL Server 2012 and later.
In order to confirm this, check the DATABASES settings of your Django app, and see if it shows 'ENGINE': 'sqlserver_ado' as the connection type. If so,
pip install django-mssql --upgrade should fix your issue (though I haven't actually tested this).
EDIT: OK, so based on additional info from your comment ('ENGINE': 'sql_server.pyodbc' in the DATABASES settings), it looks like you're actually using django-pyodbc-azure as the database connector. This driver seems to be quite Django-version dependent. Let's first find out which version is in use:
pip show django-pyodbc-azure
The version you install should be the same as the Django version. If using Django 1.8, and if the django-pyodbc-azure version shows less than that, try installing the correct version:
pip install "django-pyodbc-azure<1.9"

Would old version of mysql(5.1) caused performance issue in Django(1.11)

I'm rewritting a web application using Django 1.11. When i hooked up to my test mysql database (version 5.7), the performance is amazing. The page renders within 1 second. However, when I connect to the existing production mysql (version 5.1), the page takes more than 10 seconds.
I installed the debug toolbar, and I found out the the query time is actually not the issue. Most of the time are in the CPU.
I've eliminated the possibility of mysql performance issue by directly running the query on the database. It's not network issue either since my ping is just fine.
I am wondering whether the Django is having issues with older mysql version when Django receives the data and try to map it to objects via ORM.

Django with NoSQL database

I am working with an Django application which uses Django 1.8 version.
Most of the data we deal with is JSON formatted ones. We are trying to implement any NoSQL database.
But I see that MONGODB is not compatible for version 1.8 and over and Is there any NoSQL database that can be efficiently mapped to Django 1.8 or over ??
Thanks in advance.
NoSQL databases are not officially supported by Django itself. There are, however, a number of side project and forks which allow NoSQL functionality in Django, like Django non-rel.
You can also take a look on the wiki page which discusses some alternatives.
This is quoted from the django official documentation
Here is an interesting repo for allowing using MongoDB as your django backend. It works by compiling SQL commands into MongoDB document queries.
Most of the basic stuff like django admin, django session etc all work.
https://github.com/nesdis/djongo
Years after (2022), djongo is still the only option which works fine with Django 3.0.x as well (with some constraint restrictions) in NoSQL environment.
But now that Django's 4.0.1 major release is in the air, djongo's latest 1.3.6 (released in June 2021 according to pypi) is beginning to break. In my experience with Django==4.0.4 and djongo==1.3.6 together, almost none of the select/update queries work, and SQLDecodeError exceptions lay around in console.
djongo maintainer(s) have created paid subscription plans as well, but I have not been their customer like that so can't comment anything about the commercialized version of djongo. Rest, the open-sourced AGPL licensed djongo is the only best option for unpaying developers to use Django with MongoDB, given that the developer restricts themselves to Django 3.0.x.
I've been using Django==3.0.5 with djongo==1.3.6, to be specific here, which works fine in most of the circumstances.

Should I start a new Django app with version 1.8?

I'm about to create a new custom Django app for my organization. (I'm a brand new Django developer; this will be my first one apart from the occasional "Hello world" I've done as a prototype.)
I'm on a shared hosting provider, which indicates that for Django applications, we should use Django version 1.8 (even though 1.10 is the current version) because 1.8 is the last version that supports FastCGI. Am I setting myself up for having a worthless app a few years from now once 1.8 is no longer supported? Would one expect that by the time 1.8 is no longer supported, the shared web hosting world will have moved on to WSGI or some form of workaround? Or is that a fundamental impossibility? Will I find in a couple of years that I've developed an application that is unusable on the host I've produced it for?
Alternatively, should I be considering some other development tool for the situation I'm in? I'm on a shared host, and I'll be doing a fairly vanilla web front end / database back end style setup.
Am I setting myself up for having a worthless app?
Nope. You will have your project working, and if you ever want to upgrade and find it difficult to jump 3 version at once (1.8 LTS to 1.11 LTS) you can do it step-by-step with neat deprecation warnings. Though general compatibility between versions is usually very good. You will probably also want to have requirements.txt to recreate your virtualenv, and then just dropping away the fcgi trash.
... the shared web hosting world will have moved on to WSGI ...?
They will have to if they want to earn money. It is also quite easy to configure so there's no other "fundamental impossibility" than laziness.
Should I start a new Django app with version 1.8?
I cannot decide for you. I would rather consider changing my hosting. On the other hand there's handful of popular extensions that didn't successfully migrate their master to 1.10 yet (e.g. grappelli), which could also cause delayed migration of your own projects.
Should I be considering some other development tool?
Too general. Ever seen Flask? It's neat, but Django comes with more features out of the box.

Upgrade Django from 1.6.2 to latest version (~1.8)

So I've been tasked with upgrading a Django server from 1.6.2 to the latest (~1.8), along with upgrading Python from 2.7.3 to 3.3. I suspect this is going to break quite a bit of code. (I even need to upgrade the Ubuntu installation from 12.04 to 14.04)
I would like to migrate my Django app from the server it's currently running on (Ubuntu 12.04) to a virtual machine, and use that environment as a sandbox to make changes.
Would anyone be so kind to provide guidance on django app migration? Please let me know if you'd like me to provide any specific details.
Thank you.
Edit: If anyone would like to vote down this question because they believe I haven't done enough research, I'm very happy to add missing information, if I know what you're looking for.
Django versions from 1.5 onwards has been designed so that the same code will work on both versions of Python as in the documentation thanks to them following the six compatibility layer.
You might face some issues with code that isn't strictly related to Django components like print statements and other such parts that might have been coded in. The official Python Porting Guide should held you with that.
Django 1.8 is a LTS (Long Term Release) so it's a good idea to upgrade to it. Migrating the database might be a bit of an issue considering it's from 2.7 to 3.4 but that's in all likelihood the place you'll find most issue with. The How to Migrate is a great resource.
If I recall correctly the directory structure is a bit different in 1.6 so you'll have to move some code and files manually. I suggest having the tutorial pages for both versions 1.6 and 1.8 open and comparing the directory structure.
Going through the first 2 pages of the tutorial should give you enough of an overview to migrate the database and the settings file. This should also help with migrations.
The 3rd and 4th pages should get you through migrating the views and urls files.
The only thing I'm not familiar with is the migration of the wsgi file which has configuration information, you should be able to find some basic information about that here.
Updating your Ubuntu however won't change or affect anything at all.
Also as has been said in the comments by jape and joel, it's a good idea to use virtualenv and git.
I would like to add another suggestion based on my own experience with pushing code to a Django server :
Download the code base to your local machine and work there and once you're done and the server is working well on your machine push it all to the server at once. That way you can isolate server machine specific issues from coding issues.

Categories