django-pyodbc-azure icon indicating copy to clipboard operation
django-pyodbc-azure copied to clipboard

No results. Previous SQL was not a query. When running tests.

Open Skylude opened this issue 8 years ago • 4 comments

Django==1.9.7 django-pyodbc-azure==1.9.6.0 pyodbc==3.0.10

FreeTDS Driver v0.91 TDS_Version = 4.2

SQL Server 2012 R2

Everything seems to be working just fine on MacOSX, however when running on Ubuntu I get the following error when trying to run tests. It is successfully creating the test db but then erroring out somewhere when running the migrations. I'm not quite sure where to go from here or what steps to take to figure out what is throwing the error. Any help / suggestions would be much appreciated.

$ python manage.py test Creating test database for alias 'default'... Traceback (most recent call last): File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/utils.py", line 102, in inner return func(_args, *_kwargs) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/sql_server/pyodbc/base.py", line 585, in fetchall return self.format_rows(self.cursor.fetchall()) pyodbc.ProgrammingError: No results. Previous SQL was not a query.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/init.py", line 353, in execute_from_command_line utility.execute() File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/init.py", line 345, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv super(Command, self).run_from_argv(argv) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(_args, *_cmd_options) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute super(Command, self).execute(_args, *_options) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute output = self.handle(_args, *_options) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/commands/test.py", line 90, in handle failures = test_runner.run_tests(test_labels) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/test/runner.py", line 532, in run_tests old_config = self.setup_databases() File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/test/runner.py", line 482, in setup_databases self.parallel, *_kwargs File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/test/runner.py", line 726, in setup_databases serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True), File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db run_syncdb=True, File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/init.py", line 119, in call_command return command.execute(_args, *_defaults) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute output = self.handle(_args, *_options) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 200, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/migrations/executor.py", line 92, in migrate self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/migrations/executor.py", line 198, in apply_migration state = migration.apply(state, schema_editor) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/migrations/migration.py", line 123, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 121, in database_forwards schema_editor.remove_field(from_model, from_model._meta.get_field(self.name)) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/sql_server/pyodbc/schema.py", line 609, in remove_field index_names = self._constraint_names(model, [field.column], index=True) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 911, in _constraint_names constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/sql_server/pyodbc/introspection.py", line 294, in get_constraints for constraint, column in cursor.fetchall(): File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/utils.py", line 102, in inner return func(_args, *_kwargs) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/utils.py", line 95, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/django/db/utils.py", line 102, in inner return func(_args, **kwargs) File "/opt/virtualenv/rd-api/lib/python3.4/site-packages/sql_server/pyodbc/base.py", line 585, in fetchall return self.format_rows(self.cursor.fetchall()) django.db.utils.ProgrammingError: No results. Previous SQL was not a query.

Skylude avatar Jul 04 '16 06:07 Skylude

I had to add the following to my options in the database settings. Weird the error I was getting.

'unicode_results': True, 'extra_params': 'tds_version=8.0'

Skylude avatar Jul 04 '16 16:07 Skylude

So if I perform the above fix setting tds_version=8.0 that causes other issues like not supporting datetime2 etc. Then I run into errors getting a str back instead of a datetime. So putting the tds_version=7.4 and running my migrations on MacOSX using FreeTDS and UnixODBC it works fine. Running on Ubuntu I get the following "No results. Previous SQL was not a query.". This is happening when running the initial migration on tests.

Skylude avatar Jul 14 '16 15:07 Skylude

Same problem here on Fedora 24 during the database migrations for a Django==1.9.9 project using django-pyodbc-azure==1.9.3.0

marco-santamaria avatar Oct 18 '16 12:10 marco-santamaria

Also getting this on on Ubuntu, the migrations seem to have run but it has terminated with this error.

FalseProtagonist avatar Oct 18 '16 14:10 FalseProtagonist