Hi,
We use SQL server, which I have finally got connected to. Our DBAs will not allow Django to control the server objects using migrations and have given me a read/write user with no DDL permissions. So I need to give them a script with the basic structures needed for the admin functionality.
The config is basic out of the box Django:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'PollsterSystem.apps.PollstersystemConfig',
]
I eventually found I could issue the showmigrations command to see which migrations needed to be applied and that gave me:
showmigrations
bash -cl "/usr/bin/python3.8 /snap/pycharm-professional/244/plugins/python/helpers/pycharm/django_manage.py showmigrations /home/pmason/PycharmProjects/DjangoTutorial"
Tracking file by folder pattern: migrations
PollsterSystem
(no migrations)
admin
[ ] 0001_initial
[ ] 0002_logentry_remove_auto_add
[ ] 0003_logentry_add_action_flag_choices
auth
[ ] 0001_initial
[ ] 0002_alter_permission_name_max_length
[ ] 0003_alter_user_email_max_length
[ ] 0004_alter_user_username_opts
[ ] 0005_alter_user_last_login_null
[ ] 0006_require_contenttypes_0002
[ ] 0007_alter_validators_add_error_messages
[ ] 0008_alter_user_username_max_length
[ ] 0009_alter_user_last_name_max_length
[ ] 0010_alter_group_name_max_length
[ ] 0011_update_proxy_permissions
[ ] 0012_alter_user_first_name_max_length
contenttypes
[ ] 0001_initial
[ ] 0002_remove_content_type_name
sessions
[ ] 0001_initial
Process finished with exit code 0
But when I issue sqlmigrate admin 0001_initial I get lots of errors:
sqlmigrate admin 0001_initial
bash -cl "/usr/bin/python3.8 /snap/pycharm-professional/244/plugins/python/helpers/pycharm/django_manage.py sqlmigrate admin 0001_initial /home/pmason/PycharmProjects/DjangoTutorial"
Tracking file by folder pattern: migrations
Traceback (most recent call last):
File "/snap/pycharm-professional/244/plugins/python/helpers/pycharm/django_manage.py", line 52, in <module>
run_command()
File "/snap/pycharm-professional/244/plugins/python/helpers/pycharm/django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "/usr/lib/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/pmason/PycharmProjects/DjangoTutorial/manage.py", line 22, in <module>
main()
File "/home/pmason/PycharmProjects/DjangoTutorial/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/commands/sqlmigrate.py", line 29, in execute
return super().execute(*args, **options)
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/pmason/.local/lib/python3.8/site-packages/django/core/management/commands/sqlmigrate.py", line 65, in handle
sql_statements = loader.collect_sql(plan)
File "/home/pmason/.local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 351, in collect_sql
state = migration.unapply(state, schema_editor, collect_sql=True)
File "/home/pmason/.local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 118, in __exit__
self.execute(sql)
File "/home/pmason/.local/lib/python3.8/site-packages/mssql/schema.py", line 856, in execute
sql = str(sql)
File "/home/pmason/.local/lib/python3.8/site-packages/django/db/backends/ddl_references.py", line 201, in __str__
return self.template % self.parts
KeyError: 'include'
I’ve tried sqlmigrate admin and sqlmigrate admin 0001 and both generate the above.
Any suggestions, or is there another way of getting this SQL?
It’s not actually that far removed from MVC/MVT patterns though, so give the Access guys some credit - they may find it more intuitive than you think. From my experience the hardest part of migrating from older “legacy” (don’t like that word really) systems is not so much the new dev language/framework - it’s more the modern devops processes, use of git for version control, automated testing, CI/CD that tend to be the sticking points.