Unable to use Custom Base class
See original GitHub issueHello!
I’m trying to create a new base event My base class looks like this:
class AbstractEvent(models.Model):
jira_issue = models.CharField(max_length=20, default='NOTSYNCED')
My config looks like this:
...
SCHEDULER_BASE_CLASSES = {
'Event': ['downtime_calendar.models.AbstractEvent']
}
SCHEDULER_ADMIN_FIELDS = {
'Event': [('jira_issue',)]
}
...
But whenever I try to run the./manage.py makemigrations && ./manage.py migrate
I got a nasty error
Applying schedule.0006_auto_20171018_1520...Traceback (most recent call last):
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 101, in execute
return self.cursor.execute(query, args)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/home/gonzalo/VirtualEnvs/apcela_web_project/lib/python3.5/site-packages/MySQLdb/connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1829, "Cannot drop column 'id': needed in a foreign key constraint 'schedule_eventrelation_event_id_8c57a7b4_fk_schedule_event_id' of table 'apcela_web_app.schedule_eventrelation'")
I’m thinking that either something is missing in the documentation that I’m supposed to do, since I’m not sure why is that django migration is trying to remove the ID from the schedule_event table
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Unable to cast base class to derived class with custom attribute
I am trying to convert base type to derived type with "OfType().Cast().ToList()". Here is my method public class CosmosDBRepository<T> ...
Read more >Cannot load base class error when inheriting a form ... - MSDN
The designer inspected the following classes in the file: TextViewer --- The base class 'NIB.FormTemplate' could not be loaded.
Read more >The designer cannot be shown because base class could not ...
The designer inspected the following classes in the file: [our Windows Form class] — The base class [base class of our custom controls]...
Read more >Can't use base class and derived class functions
I have made two libraries and one test program.I have made my custom uart library.first i have included all functions for printing in...
Read more >Mixin and Custom Base Classes
Declarative includes several helper features to make this work in terms of how ... If the Base did define an attribute of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
IMO, the
_BASE_CLASSES
feature is a difficult to maintain feature with lots of unusual edge cases and unexpected consequences. I think the project should consider dropping it to ease maintainability, predictability, and consistency with other reusable Django apps. My project uses quite a few reusable Django apps and I’m not aware of any other using a similar_BASE_CLASSES
like feature, which might help explain why this is a common source of bugs (and one currently holding back Django 2.0 support). Are you aware of any other reusable Django apps with a similar feature? Do they hit the same issue?@llazzaro What are you thoughts on deprecating and removing this feature? If you agree, I’m happy to open a pull request to do so. It would certainly simplify maintenance.
@ggarcia24 The
Event
model already supports relationships to arbitrary other objects through theEventRelation
model. Have you considered using that to solve your use case?I’ve created a proof of concept of my proposal above at #377. All feedback on it is welcome.